示例#1
0
        static void Main(string[] args)
        {
            //var firstOrder = new MilkDecorator(new SugarDecorator(new Espresso()));
            //var billOfFirstOrder = $"Price of {firstOrder.GetDescription()} is {firstOrder.GetCost()} dollars";

            //var secondOrder = new Espresso();
            //var billOfSecondOrder = $"Price of {secondOrder.GetDescription()} is {secondOrder.GetCost()} dollars";

            //var thirdOrder = new SugarDecorator(new SugarDecorator(new MilkDecorator(new Espresso())));
            //var billOfThirdOrder = $"Price of {thirdOrder.GetDescription()} is {thirdOrder.GetCost()} dollars";


            //Console.WriteLine(billOfFirstOrder);
            //Console.WriteLine(billOfSecondOrder);
            //Console.WriteLine(billOfThirdOrder);
            //Console.ReadKey();

            IBeverage espressoBeverage          = new GeneralBeverage(Beverages.Espresso.ToString(), (int)Beverages.Espresso);
            IBeverage espressoWithMilk          = new MilkDecorator(espressoBeverage);
            IBeverage espressoWithMilkWithSugar = new SugarDecorator(espressoWithMilk);

            espressoWithMilkWithSugar.GetCost();



            IBeverage deCafBeverage          = new GeneralBeverage(Beverages.DeCaf.ToString(), (int)Beverages.DeCaf);
            IBeverage deCafWithMilk          = new MilkDecorator(deCafBeverage);
            IBeverage deCafWithMilkWithSugar = new SugarDecorator(deCafWithMilk);

            deCafWithMilkWithSugar.GetCost();
            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            var testKaffe = new SugarDecorator(new MilkDecorator(new Coffee()));


            Console.WriteLine(testKaffe.GetDescription());
            Console.WriteLine(testKaffe.GetCost());

            var testKaffeasd = new SprinklesDecorator(testKaffe);

            Console.WriteLine(testKaffeasd.GetDescription());
            Console.WriteLine(testKaffeasd.GetCost());
            var doubleSprinkles = new SprinklesDecorator(testKaffeasd);

            Console.WriteLine(doubleSprinkles.GetDescription());
            Console.WriteLine(doubleSprinkles.GetCost());


            Console.ForegroundColor = ConsoleColor.White;
            //test of adding behaviour at runtime
            Console.WriteLine("If you want a Tea, press T. if you want a Coffee, press C. This resets the order though");
            Console.WriteLine("test of adding behaviour at runtime(you have to press the buttons twice), press M to add milk, press S to add sugar and press W to add sprinkles. for wauw effect.");
            IDrink DrinkTest = new Coffee();

            //ConsoleKeyInfo read1 = Console.ReadKey();
            do
            {
                ConsoleKeyInfo read = Console.ReadKey();
                if (read.Key == ConsoleKey.M)
                {
                    DrinkTest = new MilkDecorator(DrinkTest);
                }
                if (read.Key == ConsoleKey.S)
                {
                    DrinkTest = new SugarDecorator(DrinkTest);
                }
                if (read.Key == ConsoleKey.W)
                {
                    DrinkTest = new SprinklesDecorator(DrinkTest);
                }
                if (read.Key == ConsoleKey.C)
                {
                    DrinkTest = new Coffee();
                    Console.ForegroundColor = ConsoleColor.White;
                }
                if (read.Key == ConsoleKey.T)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    DrinkTest = new Tea();
                }


                Console.WriteLine();
                Console.WriteLine(DrinkTest.GetDescription());
                Console.WriteLine(DrinkTest.GetCost());
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
示例#3
0
        static void Main(string[] args)
        {
            var firstOrder       = new MilkDecorator(new SugarDecorator(new Espresso()));
            var billOfFirstOrder = $"Price of {firstOrder.GetDescription()} is {firstOrder.GetCost()} dollars";

            var secondOrder       = new Espresso();
            var billOfSecondOrder = $"Price of {secondOrder.GetDescription()} is {secondOrder.GetCost()} dollars";

            var thirdOrder       = new SugarDecorator(new SugarDecorator(new MilkDecorator(new Espresso())));
            var billOfThirdOrder = $"Price of {thirdOrder.GetDescription()} is {thirdOrder.GetCost()} dollars";


            Console.WriteLine(billOfFirstOrder);
            Console.WriteLine(billOfSecondOrder);
            Console.WriteLine(billOfThirdOrder);
            Console.ReadKey();
        }
示例#4
0
        static void Main(string[] args)
        {
            Console.ReadLine();
            Console.WriteLine("\nLet's start with a basic cookie\n");

            // Create a basic cookie
            Cookie baseCookie = new Cookie();

            PrintCookieInformation(baseCookie);

            Console.ReadLine();
            Console.WriteLine("\nThat cookie needs something sweet. Smother it with sugar!\n");

            // Add sugar to it!
            SugarDecorator sugarCookie = new SugarDecorator(baseCookie);

            PrintCookieInformation(sugarCookie);

            Console.ReadLine();
            Console.WriteLine("\nOh look, another cookie!\n");

            // Create a second cookie. This will be covered only in bacon
            Cookie baseCookie2 = new Cookie();

            PrintCookieInformation(baseCookie2);

            Console.ReadLine();
            Console.WriteLine("\n Now ruin it with some oatmeal...\n");

            // Let now add oatmeal on it
            OatmealDecorator oatmealCookie = new OatmealDecorator(baseCookie2);

            PrintCookieInformation(oatmealCookie);

            Console.ReadLine();
            Console.WriteLine("We can also add decorators at any point. Let's add some bacon to that first sugar-covered cookie:\n");

            // Mmm...bacon
            BaconDecorator baconCookie = new BaconDecorator(sugarCookie);

            PrintCookieInformation(baconCookie);

            Console.ReadLine();
        }