Ejemplo n.º 1
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()}");
        }
Ejemplo n.º 2
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());
        }
Ejemplo n.º 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();
        }