Beispiel #1
0
        static void Main(string[] args)
        {
            Car theCar = new CompactCar();

            theCar = new LeatherSeats(theCar);

            Console.WriteLine(theCar.GetDescription());
            Console.WriteLine($"${theCar.GetCarPrice()}");
            Console.ReadKey();
        }
Beispiel #2
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}");
        }
Beispiel #3
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}");
        }
Beispiel #4
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();
        }