Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Car theCar = new CompactCar();

            theCar = new Sunroof(theCar);

            Console.WriteLine(theCar.GetDescription());
            Console.WriteLine(theCar.GetPrice());
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Car c = new CompactCar();

            c = new LeatherDecorator(c);
            c = new SunRoof(c);

            System.Console.WriteLine(c.Description);
            System.Console.WriteLine(c.Price);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Car theCar = new CompactCar();

            theCar = new LeatherSeats(theCar);

            Console.WriteLine(theCar.GetDescription());
            Console.WriteLine($"${theCar.GetCarPrice()}");
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        public static void Main(string[] args)
        {
            Car theCar = new CompactCar();

            theCar = new Navigation(theCar);
            theCar = new Sunroof(theCar);
            theCar = new LeatherSeats(theCar);

            Console.WriteLine(theCar.GetDescription());
            Console.WriteLine($"{theCar.GetCarPrice():C2}");
        }
Ejemplo n.º 5
0
        public static void Main()
        {
            Car compactCar = new CompactCar();

            compactCar = new Navigation(compactCar);
            compactCar = new Sunroof(compactCar);
            compactCar = new LeatherSeats(compactCar);

            Console.WriteLine(compactCar.GetDescription());
            Console.WriteLine($"{compactCar.GetCarPrice():C2}");
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            Car compactCar = new CompactCar();

            compactCar = new Navigation(compactCar);
            compactCar = new Sunroof(compactCar);

            Console.WriteLine(compactCar.GetDescription());
            Console.WriteLine(compactCar.GetPrice());

            Console.ReadLine();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            Car theCar = new CompactCar();     //10,000

            theCar = new Navigation(theCar);   //5,000
            theCar = new Sunroof(theCar);      //2,500
            theCar = new LeatherSeats(theCar); //2,500

            //if you comment out each of Nav/Sun/Leather,
            //you'll see the total price change accordingly.
            //each new decorator/wrapper will add to what was already there.
            //ie, the price, plus whatever the extra cost is.

            Console.WriteLine(theCar.GetDescription());
            Console.WriteLine($"{theCar.GetCarPrice():C2}"); //20,000
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        internal void Test()
        {
            Console.WriteLine($"\nExecution of {GetType().Name} \n");

            var compactCar = new CompactCar();

            var decorators = new List <ICarDecorator>
            {
                new NavigationDecorator(),
                new SunroofDecorator(),
                new LeatherSeatsDecorator()
            };

            decorators.ForEach(d => d.Decorate(compactCar));

            Console.WriteLine(compactCar.Description);
            Console.WriteLine($"{compactCar.Price.ToString("C2")}");
        }
Ejemplo n.º 9
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")}");
        }
Ejemplo n.º 10
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();
        }