Пример #1
0
        /// <summary>
        /// 装饰
        /// </summary>
        static void Decorator()
        {
            Console.WriteLine($"装饰{Environment.NewLine}-------------------------------------------");

            Component human = new Human();  //一个人

            human = new Clothes(human);     //穿衣服
            human = new Clothes(human);     //在穿一件衣服
            human = new Trouser(human);     //穿裤子
            human = new Shoe(human);        //穿鞋
            //Component human = new Shoe(new Trouser(new Clothes(new Human())));

            Console.WriteLine(human.ShowMyself());
            Console.ReadKey();
        }
Пример #2
0
    void TestDecorator()
    {
        Person component = new Person("Alfred");

        Debug.Log("First Clothes");

        Trouser trouser = new Trouser();
        TShirts tshirts = new TShirts();

        trouser.Decorate(component);
        tshirts.Decorate(trouser);
        tshirts.Show();

        Debug.Log("Second Clothes:");
        Sneaker sneaker = new Sneaker();
        Shoes   shoes   = new Shoes();

        sneaker.Decorate(component);
        shoes.Decorate(sneaker);
        shoes.Show();
    }
Пример #3
0
 public Client(DressFactory dressFactory)
 {
     _shirt   = dressFactory.GetShirt();
     _trouser = dressFactory.GetTrouser();
 }