예제 #1
0
        public static void UsingDesignPattern()
        {
            HondaCity   car         = new HondaCity();
            ConcreteCar hondaAccord = new ConcreteCar("Honda", "Accord", 25999.00);
            ConcreteCar hondaCivic  = new ConcreteCar("Honda", "Civic", 21999.00);

            List <DecoratorPattern.Vehicle> vehicleList = new List <DecoratorPattern.Vehicle>();

            vehicleList.Add(hondaAccord);
            vehicleList.Add(hondaCivic);
            vehicleList.Add(car);

            List <SpecialOffer> specialOffers = new List <SpecialOffer>();

            foreach (DecoratorPattern.Vehicle v in vehicleList)
            {
                SpecialOffer offer = new SpecialOffer(v);
                offer.DiscountPercentage = 25;
                offer.Offer = "25 % discount";

                specialOffers.Add(offer);
            }


            foreach (SpecialOffer o in specialOffers)
            {
                Console.WriteLine("The offer: {1} New price: {0} For {2} {3} with {4}% off.", o.Price, o.Offer, o.Make, o.Model, o.DiscountPercentage);
            }
            // Special offer

            //Console.WriteLine("{1} @ Diwali Special Offer and price are : {0} ", offer.Price, offer.Offer);
        }
예제 #2
0
        static void Main(string[] args)
        {
            // Basic vehicle
            HondaCity car = new HondaCity();

            Console.WriteLine("Honda City base price are : {0}", car.Price);

            // Special offer
            SpecialOffer offer = new SpecialOffer(car);

            offer.DiscountPercentage = 25;
            offer.Offer = "25 % discount";

            Console.WriteLine("{1} @ Diwali Special Offer and price are : {0} ", offer.Price, offer.Offer);
            Console.ReadKey();
        }