Exemple #1
0
        internal void Test()
        {
            Console.WriteLine($"\nExecution of {GetType().Name} \n");

            ICar compactCar = new CompactCar();

            compactCar = new NavigationDecorator(compactCar);
            compactCar = new SunroofDecorator(compactCar);
            compactCar = new LeatherSeatsDecorator(compactCar);

            Console.WriteLine(compactCar.Description);
            Console.WriteLine($"{compactCar.Price.ToString("C2")}");


            // -------------------- OR --------------------

            //var compactCar2 = new LeatherSeatsDecorator(new SunroofDecorator(new NavigationDecorator(new CompactCar())));

            //Console.WriteLine(compactCar2.Description);
            //Console.WriteLine($"{compactCar.Price.ToString("C2")}");
        }
Exemple #2
0
        static void Main()
        {
            Car compactCar = new CompactCar();

            Console.WriteLine($"Description: {compactCar.GetDescription()}");
            Console.WriteLine($"Description: {compactCar.GetCarPrice()}");
            Console.WriteLine();

            Car fullSizeCar = new FullSizeCar();

            Console.WriteLine($"Description: {fullSizeCar.GetDescription()}");
            Console.WriteLine($"Description: {fullSizeCar.GetCarPrice()}");
            Console.WriteLine();

            Car otherCompactCarWithDecorators = new CompactCar();

            otherCompactCarWithDecorators = new LeatherSeatDecorator(otherCompactCarWithDecorators);
            otherCompactCarWithDecorators = new NavigationDecorator(otherCompactCarWithDecorators);
            Console.WriteLine($"Description: {otherCompactCarWithDecorators.GetDescription()}");
            Console.WriteLine($"Description: {otherCompactCarWithDecorators.GetCarPrice()}");

            Console.Read();
        }