Exemplo n.º 1
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
        }
Exemplo n.º 2
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
        }
Exemplo n.º 3
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();
        }