Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface IFuel
- {
- Int32 Level { get; }
- void Refill();
- }
- public abstract class Vehicle
- {
- public IFuel Fuel { get; }
- public Vehicle(IFuel fuel)
- {
- Fuel = fuel;
- }
- }
- public class GasFuel : IFuel
- {
- public Int32 Level { get; private set; }
- public void Refill()
- {
- Console.WriteLine("Gas Refilled.");
- Level = 100;
- }
- public GasFuel() : base()
- {
- }
- }
- public class ElectricFuel : IFuel
- {
- public Int32 Level { get; private set; }
- public void Refill()
- {
- Console.WriteLine("Charged Battery.");
- Level = 100;
- }
- }
- //What you're proposing, which is a bit silly.
- public class ElectricCar : Vehicle
- {
- public ElectricCar():base(new ElectricFuel())
- {
- }
- }
- public class GasCar : Vehicle
- {
- public GasCar():base(new GasFuel())
- {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement