Example #1
0
        static void Main(string[] args)
        {
            //下订单:2巧克力 1牛奶 的 longblack

            //1 longblack
            Drink order = new LongBlack();

            Console.WriteLine("费用:\t" + order.Cost());
            Console.WriteLine("描述:\t" + order.GetDescription());

            //2 加牛奶
            order = new Milk(order);
            Console.WriteLine("费用:\t" + order.Cost());
            Console.WriteLine("描述:\t" + (order as Decorator).GetDescription());

            //3 加巧克力
            order = new Chocolate(order);
            Console.WriteLine("费用:\t" + order.Cost());
            Console.WriteLine("描述:\t" + (order as Decorator).GetDescription());

            //3 加巧克力
            order = new Chocolate(order);
            Console.WriteLine("费用:\t" + order.Cost());
            Console.WriteLine("描述:\t" + (order as Decorator).GetDescription());

            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            Beverage beverage = new Espresso();

            beverage = new Milk(beverage);
            beverage = new Chocolate(beverage);

            Console.WriteLine(beverage.Description());
            Console.WriteLine(beverage.Cost());
        }