Esempio n. 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();
        }
Esempio n. 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);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Beverage beverage = new DarkRoast();

            beverage = new SoyDecorator(beverage);
            Console.WriteLine(beverage.GetDescription());
            beverage = new SoyDecorator(beverage);
            beverage = new MilkDecorator(beverage);
            Console.WriteLine($"Name: {beverage.GetDescription()}  Price: {beverage.GetPrice()}");
        }
Esempio n. 4
0
        // Simulating a coffee shop where you could combine different ingredients at runtime

        static void Main(string[] args)
        {
            var coffee = new DecafCoffee();

            Console.WriteLine(coffee.Cost());
            Console.WriteLine(coffee.GetDescription());

            ICoffee decoratedCoffee = new MilkDecorator(coffee);

            Console.WriteLine(decoratedCoffee.Cost());
            Console.WriteLine(decoratedCoffee.GetDescription());

            decoratedCoffee = new CreamDecorator(decoratedCoffee);

            Console.WriteLine(decoratedCoffee.Cost());
            Console.WriteLine(decoratedCoffee.GetDescription());
        }
Esempio n. 5
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();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            IBeverage coffee = new Coffee
            {
                Temperatore = 99,
                Volume      = 120
            };
            var component = new CoffeeManager();

            Console.WriteLine("Component with no decorators: ");
            Console.WriteLine(component.Prepare(coffee));

            Console.WriteLine("----------------------------------------------");
            Console.WriteLine("Component with 2 decorators: ");
            var coffeDeluxDecorators = new MilkDecorator(new SyrupDecorator(component));

            Console.WriteLine(coffeDeluxDecorators.Prepare(coffee));
            Console.Read();
        }