Exemple #1
0
        static void Main(string[] args)
        {
            //首先实现一个具体的猫
            Animal duck = new Duck
            {
                FootNum  = 2,
                HaveTail = true,
                Name     = "鸭子"
            };


            //再装饰一个日志
            duck = new LogDecorator(duck);
            //装饰一个时间戳
            duck = new TimeStampDecorator(duck);

            duck.Sound();

            Console.Read();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Dish dish = new Chicken();

            Console.WriteLine(dish.GetDescription() + " $" + dish.cost());

            Dish dish2 = new Duck();

            dish2 = new Sauce(dish2);

            Console.WriteLine(dish2.GetDescription() + " $" + dish2.cost());

            Dish dish3 = new Turkey();

            dish3 = new Sauce(dish3);
            dish3 = new Pepper(dish3);

            Console.WriteLine(dish3.GetDescription() + " $" + dish3.cost());

            Console.ReadLine();
        }