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(); }
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); }
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(); }