예제 #1
0
        static void Main()
        {
            Person jack = new Person("杰克");

            Console.WriteLine("第一种装扮:");

            // 创建装饰物:
            // ----------
            var shirts     = new TShirts();
            var sneakers   = new Sneakers();
            var bigtrouser = new BigTrouser();

            // 装饰过程:
            // --------
            // 机理:B对象装饰A、C对象装饰B、D对象装饰C ..
            //      核心在于都执行了base.Show() 即Finery.Show()
            shirts.Decorator(jack);
            sneakers.Decorator(shirts);
            bigtrouser.Decorator(sneakers);

            // 打印
            bigtrouser.Show();

            Console.Read();
        }
예제 #2
0
        private static void NewMethod1()
        {
            Person pr = new Person("Leng");

            Console.WriteLine("first look");

            Finery tShirts = new TShirts();

            tShirts.Show();
            Finery bigTrouser = new BigTrouser();

            bigTrouser.Show();
            Finery sneakers = new Sneakers();

            sneakers.Show();
            pr.Show();

            Console.WriteLine("\nsecond look");
            Finery suit = new Suit();

            suit.Show();
            Finery tie = new Tie();

            tie.Show();
            Finery leatherShoes = new LeatherShoes();

            leatherShoes.Show();
            pr.Show();

            Console.Read();
        }
예제 #3
0
        static void Main(string[] args)
        {
            Person     p  = new Person("Ben");
            TShirts    ts = new TShirts();
            BigTrouser bt = new BigTrouser();

            ts.Decorate(p);
            bt.Decorate(ts);
            bt.Show();
        }
예제 #4
0
        static void Main(string[] args)
        {
            Person p = new Person("小明");
            p.Show();
            Console.WriteLine();

            TShirts ts = new TShirts();
            ts.Decorate(p);
            ts.Show();

            BigTrouser dt = new BigTrouser();
            dt.Show();
            Console.WriteLine();
            dt.Decorate(p);
            dt.Show();

            dt.Decorate(ts);
            dt.Show();
        }
예제 #5
0
        static void Main(string[] args)
        {
            Person p = new Person("小明");

            p.Show();
            Console.WriteLine();

            TShirts ts = new TShirts();

            ts.Decorate(p);
            ts.Show();

            BigTrouser dt = new BigTrouser();

            dt.Show();
            Console.WriteLine();
            dt.Decorate(p);
            dt.Show();

            dt.Decorate(ts);
            dt.Show();
        }