コード例 #1
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();
        }
コード例 #2
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();
        }
コード例 #3
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();
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: ElvinChan/DesignPattern
        static void Main(string[] args)
        {
            #region 基本用法(对应Basic.cs)
            ConcreteComponent c = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

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

            d2.Operation();
            #endregion

            #region 具体实例(对应Example.cs)
            Person xc = new Person("小菜");
            Console.WriteLine("\n第一种装扮:");

            Sneaker pqx = new Sneaker();
            BigTrouser kk = new BigTrouser();
            TShirt dtx = new TShirt();

            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.ReadLine();
            #endregion
        }
コード例 #5
0
        static void Main(string[] args)
        {
            #region 基本用法(对应Basic.cs)
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

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

            d2.Operation();
            #endregion

            #region 具体实例(对应Example.cs)
            Person xc = new Person("小菜");
            Console.WriteLine("\n第一种装扮:");

            Sneaker    pqx = new Sneaker();
            BigTrouser kk  = new BigTrouser();
            TShirt     dtx = new TShirt();

            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.ReadLine();
            #endregion
        }
コード例 #6
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();
        }