Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //我买了个苹果手机
            Phone phone = new ApplePhone();

            //现在想贴膜了
            Decorator applePhoneWithSticker = new Sticker(phone);

            //扩展贴膜行为
            applePhoneWithSticker.Print();
            Console.WriteLine("-------------------------\n");

            //现在我想有挂件了
            Decorator applePhoneWithAccessories = new Accessories(phone);

            //扩展手机挂件行为
            applePhoneWithAccessories.Print();
            Console.WriteLine("-------------------------\n");


            //现在我同时有贴膜和手机挂件
            Sticker     sticker = new Sticker(phone);
            Accessories applePhoneWithAccessoriesAndSticker = new Accessories(sticker);

            applePhoneWithAccessoriesAndSticker.Print();
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Phone     ap        = new Applephone();
            Decorator decorator = new Sticker(ap);

            decorator.Print();

            Decorator apa = new Accessories(ap);

            apa.Print();

            Sticker     s           = new Sticker(ap);
            Accessories accessories = new Accessories(s);

            accessories.Print();

            Console.ReadKey();
        }