private void addEngine(ICar _car) { BMWCar car = (BMWCar)_car; car.Engine = "Patrol engine"; Console.WriteLine("Patrol engine added."); }
static void Main(string[] args) { ICar bmwCar1 = new BMWCar(); bmwCar1.ManufactureCar(); Console.WriteLine(bmwCar1 + "\n"); Console.WriteLine("enter the type of engine you want"); string engine = Console.ReadLine(); switch (engine.ToLower()) { case "petrolengine": PetrolCarDecorator carwithPetrolEngine = new PetrolCarDecorator(bmwCar1); carwithPetrolEngine.ManufactureCar(); break; case "dieselengine": DieselCarDecorator carWithDieselEngine = new DieselCarDecorator(bmwCar1); carWithDieselEngine.ManufactureCar(); break; default: break; } Console.ReadKey(); }
public void AddEngine(ICar car) { if (car is BMWCar) { BMWCar BMWCar = (BMWCar)car; BMWCar.Engine = "Petrol Engine"; Console.WriteLine("PetrolCarDecorator added Petrol Engine to the Car : " + car); } }
static void Main(string[] args) { ICar bmwCar = new BMWCar(); bmwCar.ManufactureCar(); PatrolEngineDecorator decorateEngine = new PatrolEngineDecorator(bmwCar); decorateEngine.ManufactureCar(); Console.ReadKey(); }