public void Main()
        {
            //Create EconomyCar 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();
        }
Exemplo n.º 2
0
        /*
         *
         * Ref : https://www.c-sharpcorner.com/UploadFile/damubetha/decorator-pattern-in-csharp/
         *
         * Definition : The Decorator Pattern provides a flexible alternative to sub classing for extending functionality dynamically.
         */
        static void Main(string[] args)
        {
            ICar economyCar = new EconomyCar();

            // Wrapping an economy car with basic accessories.
            CarAccessoriesDecorator objAccessoriesDecorator = new BasicAccessories(economyCar);

            // Wrapping the economy car with sports accessories also.
            objAccessoriesDecorator = new SportsAccessories(objAccessoriesDecorator);

            // Wrapping the economy car with luxury accessories.
            objAccessoriesDecorator = new AdvancedAccessories(objAccessoriesDecorator);

            Console.WriteLine(" Car details : " + objAccessoriesDecorator.GetDescription());
            Console.WriteLine(" ");
            Console.WriteLine("Total Price : " + objAccessoriesDecorator.GetCost());
            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            ICar economyCar = new EconomyCar();

            ICar basicEconomyCar = new BasicAccessories(economyCar);

            ICar advancedEconomyCar = new AdvancedAccessories(basicEconomyCar);

            Console.WriteLine("Детайли: " + advancedEconomyCar.GetDescription());
            Console.WriteLine("Волан: " + advancedEconomyCar.GetSteeringWheel());
            Console.WriteLine("Тапицерия: " + advancedEconomyCar.GetUpholstery());
            Console.WriteLine("Климатик: " + advancedEconomyCar.GetConditioning());
            Console.WriteLine("Цвят: " + advancedEconomyCar.GetColor());
            Console.WriteLine("Пълна цена: " + advancedEconomyCar.GetCost());

            ICar sportEconomyCar = new SportsAccessories(advancedEconomyCar);

            Console.WriteLine("Детайли: " + sportEconomyCar.GetDescription());
            Console.WriteLine("Волан: " + sportEconomyCar.GetSteeringWheel());
            Console.WriteLine("Тапицерия: " + sportEconomyCar.GetUpholstery());
            Console.WriteLine("Климатик: " + sportEconomyCar.GetConditioning());
            Console.WriteLine("Цвят: " + sportEconomyCar.GetColor());
            Console.WriteLine("Пълна цена: " + sportEconomyCar.GetCost());
        }