Example #1
0
        public static void DecoratorDemo()
        {
            // Create EcomomyCar instance.
            ICar objCar = new EconomyCar();

            CarAccessoriesDecorator objAccessoriesDecorator = new AdvancedAccessories(objCar);

            objAccessoriesDecorator = new SportAccessories(objAccessoriesDecorator);

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

            Console.Read();
        }
Example #2
0
        public static void DecoratorPattern()
        {
            //Create EcomomyCar instance.
            ICar objCar = new EconomyCar();

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

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

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

            Console.Read();
        }