Example #1
0
        static void Main(string[] args)
        {
            //Create EcomomyCar instance.
            ICar objCar = new EconomyCar();

            //Wrp EconomyCar instancw with BasicAccessories.
            CarAccessoriesDecorator objAccessoriesDecorator = new BasicAccessories(objCar);

            //Wrap EconomyCar instance with AdvancedAccessories instance.
            objAccessoriesDecorator = new AdvancedAccessories(objAccessoriesDecorator);

            Console.Write("Car Detials: " + objAccessoriesDecorator.GetDescription());
            Console.WriteLine("\n\n");
            Console.Write("Total Price: " + objAccessoriesDecorator.GetCost());

            Console.Read();
        }
Example #2
0
        static void Main(string[] args)
        {
            //calling decorator

            ICar car = new EconomyCar();

            CarAccessoriesDecorator decorator = new BasicAccessories(car);

            decorator = new AdvanceAccessories(decorator);

            Console.WriteLine($"Car Details : { decorator.GetDescription()}");
            Console.WriteLine($"Car Cost : { decorator.GetCost()}");

            car       = new SuperLuxuryCar();
            decorator = new SuperLuxuryAccessories(car);

            Console.WriteLine($"Super Car Details : { decorator.GetDescription()}");
            Console.WriteLine($"Super Car Cost : { decorator.GetCost()}");

            Console.ReadKey();
        }