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