Exemplo n.º 1
0
        static void Main(string[] args)
        {
            DrinkBase milkTea = new MilkTea();

            milkTea = new Pearl(milkTea);
            milkTea = new Pudding(milkTea);
            Console.WriteLine($"Desc: {milkTea.Desc}");
            Console.WriteLine($"Total Cost: {milkTea.TotalCost}");

            DrinkBase fruitTea = new FruitTea();

            fruitTea = new Apple(fruitTea);
            fruitTea = new Peach(fruitTea);
            Console.WriteLine($"Desc: {fruitTea.Desc}");
            Console.WriteLine($"Total Cost: {fruitTea.TotalCost}");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // 买一杯果汁
            BaseDrink juice = new JuiceDrink();

            Console.WriteLine($"{juice.GetName()}");

            // 加椰果
            BaseCondiment last = new CoconutGrain(juice);

            Console.WriteLine($"name:{last.GetName()},price:{last.GetPrice()}");

            // 加布丁
            last = new Pudding(last);

            Console.WriteLine($"name:{last.GetName()},price:{last.GetPrice()}");

            Console.ReadLine();
        }