コード例 #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
ファイル: Program.cs プロジェクト: lgy2014/DesignPattern
        static void Main(string[] args)
        {
            Person xc = new Person("小菜");

            Console.WriteLine("\n第一种装扮:");
            Sneakers   pqx = new Sneakers();
            BigTrouser kk  = new BigTrouser();
            TShirts    dtx = new TShirts();

            pqx.Decorate(xc);
            kk.Decorate(pqx);
            dtx.Decorate(kk);
            dtx.Show();

            Console.WriteLine("\n第二种装扮");

            LeatherShoes px = new LeatherShoes();
            Tie          ld = new Tie();
            Suit         xz = new Suit();

            px.Decorate(xc);
            ld.Decorate(px);
            xz.Decorate(ld);
            xz.Show();

            Console.ReadKey();
        }
コード例 #3
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();
        }
コード例 #4
0
        private static void NewMethod()
        {
            Person person = new Person("Leng");

            Console.WriteLine("first look");
            Sneakers   sneakers = new Sneakers();
            BigTrouser trouser  = new BigTrouser();
            TShirts    tShirts  = new TShirts();

            //Decoration process
            sneakers.Decorate(person);
            trouser.Decorate(sneakers);
            tShirts.Decorate(trouser);
            tShirts.Show();

            Console.WriteLine("\nsecond look");
            LeatherShoes leatherShoes = new LeatherShoes();
            Tie          tie          = new Tie();
            Suit         suit         = new Suit();

            //Decoration process
            leatherShoes.Decorate(person);
            tie.Decorate(leatherShoes);
            suit.Decorate(tie);
            suit.Show();

            Console.Read();
        }
コード例 #5
0
        public static void Main(string[] args)
        {
            var person = new Person("Bryan");

            Console.WriteLine("第一種裝扮");

            Finery tShirts    = new TShirts();
            Finery bigTrouser = new BigTourser();
            Finery sneakers   = new Sneakers();

            tShirts.Decorate(person);
            bigTrouser.Decorate(tShirts);
            sneakers.Decorate(bigTrouser);
            sneakers.Show();

            Console.WriteLine("第二種裝扮");
            Finery suit         = new Suit();
            Finery tie          = new Tie();
            Finery leatherShoes = new LeatherShoes();

            suit.Decorate(person);
            tie.Decorate(suit);
            leatherShoes.Decorate(tie);
            leatherShoes.Show();

            Console.Read();
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: benxuhuang/designPatterns
        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();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            Person     ps = new Person("Harkey");
            TShirts    ts = new TShirts();
            BigTrouser bt = new BigTrouser();
            NikeShoes  ns = new NikeShoes();

            ns.Decorate(ps);
            bt.Decorate(ns);
            ts.Decorate(bt);
            ts.Show();
        }
コード例 #8
0
        static void Main(string[] args)
        {
            Person xc = new Person("小李");

            TShirts      ts = new TShirts();
            BigTrouser   bt = new BigTrouser();
            WearSneakers ws = new WearSneakers();

            ts.Decoteter(xc);
            bt.Decoteter(ts);
            ws.Decoteter(bt);
            ws.Show();
            Console.ReadKey();
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: Jeffiy/DesignPatterns
        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();
        }
コード例 #10
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();
        }
コード例 #11
0
        static void Main(string[] args)
        {
            var c  = new ConcreteComponent();
            var d1 = new ConcreteDecoratorA();
            var d2 = new ConcreteDecoratorB();

            d1.SetComponent(c);
            d2.SetComponent(d1);
            d2.Operation();

            //範例
            Person xc = new Person("小菜");

            Console.WriteLine("第一種裝扮");
            var kk  = new BigTrouser();
            var dtx = new TShirts();

            kk.Decorate(xc);
            dtx.Decorate(kk);
            dtx.Show();

            Console.ReadLine();
        }
コード例 #12
0
        static void Main(string[] args)
        {
            Person person = new Person("小菜");

            Console.WriteLine("第一種裝扮:");
            Finery tShirts    = new TShirts();
            Finery bigTrouser = new BigTrouser();
            Finery sneakers   = new Sneakers();

            sneakers.Decorate(person);
            bigTrouser.Decorate(sneakers);
            tShirts.Decorate(bigTrouser);
            tShirts.Show();

            Console.WriteLine("\n第二種裝扮:");
            Finery suit         = new Suit();
            Finery tie          = new Tie();
            Finery leatherShoes = new LeatherShoes();

            suit.Decorate(person);
            tie.Decorate(suit);
            leatherShoes.Decorate(tie);
            leatherShoes.Show();

            Console.WriteLine("\n");

            Component component  = new ConcreteComponent();
            Decorator decoratorA = new ConcreteDecoratorA();
            Decorator decoratorB = new ConcreteDecoratorB();

            decoratorA.SetComponent(component);
            decoratorB.SetComponent(decoratorA);
            decoratorB.Operation();

            Console.ReadLine();
        }