Example #1
0
        //static void Main(string[] args)
        //{
        //    Person person = new Person("小菜");
        //    Console.WriteLine("\n 第一种装扮: ");

        //    person.WearTShirts();
        //    person.WearBigTrouser();
        //    person.WearSneakers();
        //    person.Show();

        //    Console.WriteLine("\n 第二种装扮: ");
        //    person.WearSuit();
        //    person.WearTie();
        //    person.WearLeatherShoes();
        //    person.Show();

        //    Console.Read();
        //}
        #endregion

        #region 考虑开放-封闭原则,拆解后的客户端实现
        //static void Main(string[] args)
        //{
        //    Person person = new Person("小菜");
        //    Console.WriteLine("\n 第一种装扮: ");

        //    Finery dtx = new TShirts();
        //    Finery kk = new BigTrouser();
        //    Finery pqx = new Sneakers();
        //    dtx.Show();
        //    kk.Show();
        //    pqx.Show();
        //    person.Show();

        //    Console.WriteLine("\n 第二种装扮: ");
        //    Finery xz = new Suit();
        //    Finery ld = new Tie();
        //    Finery px = new LeatherShoes();
        //    xz.Show();
        //    ld.Show();
        //    px.Show();
        //    person.Show();

        //    Console.Read();
        //}
        #endregion

        #region 使用装饰模式后的客户端实现
        static void Main(string[] args)
        {
            Person person = new Person("小菜");

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

            Finery pqx = new Sneakers();
            Finery dtx = new TShirts();
            Finery kk  = new BigTrouser();

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

            Console.WriteLine("\n 第二种装扮: ");
            Finery px = new LeatherShoes();
            Finery ld = new Tie();
            Finery xz = new Suit();

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

            Console.Read();
        }
Example #2
0
        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.Read();
        }
        static void Main(string[] args)
        {
            Person       p            = new Person("小明");
            TShirt       tShirt       = new TShirt();
            BigTrouser   bigTrouser   = new BigTrouser();
            Tie          tie          = new Tie();
            LeatherShoes leatherShoes = new LeatherShoes();

            tShirt.Decorate(p);
            tie.Decorate(tShirt);
            bigTrouser.Decorate(tie);
            leatherShoes.Decorate(bigTrouser);

            leatherShoes.Show();
            Console.ReadKey();
        }
Example #4
0
        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.WriteLine("\n第三种装扮:");
            Sneakers pqx2 = new Sneakers();
            LeatherShoes px2 = new LeatherShoes();
            BigTrouser kk2 = new BigTrouser();
            Tie ld2 = new Tie();

            pqx2.Decorate(xc);
            px2.Decorate(pqx);
            kk2.Decorate(px2);
            ld2.Decorate(kk2);

            ld2.Show();

            Console.Read();
        }