public void AddEngine(ICar car) { if (car is BMWCar) { BMWCar BMWCar = (BMWCar)car; BMWCar.Engine = "Diesel Engine"; Console.WriteLine("DieselCarDecorator added Diesel Engine to the Car : " + car); } }
static void Main(string[] args) { ICar bmwCar1 = new BMWCar(); bmwCar1.ManufactureCar(); Console.WriteLine(bmwCar1 + "\n"); DieselCarDecorator carWithDieselEngine = new DieselCarDecorator(bmwCar1); carWithDieselEngine.ManufactureCar(); Console.WriteLine(); ICar bmwCar2 = new BMWCar(); PetrolCarDecorator carWithPetrolEngine = new PetrolCarDecorator(bmwCar2); carWithPetrolEngine.ManufactureCar(); Console.ReadKey(); }