Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ConcreteComponent concreteComponent = new ConcreteComponent();
            //实例化两个装饰器
            ConcreteDecoratorA concreteDecoratorA = new ConcreteDecoratorA();
            ConcreteDecoratorB concreteDecoratorB = new ConcreteDecoratorB();

            //对concreteComponent对象进行装饰
            concreteDecoratorA.SetComponent(concreteComponent);
            concreteDecoratorB.SetComponent(concreteComponent);

            //显示装饰后的结果
            Console.WriteLine("经过装饰器A装饰后的操作:");
            concreteDecoratorA.Operation();
            Console.WriteLine("经过装饰器B装饰后的操作:");
            concreteDecoratorB.Operation();

            //演员与化妆师举例
            Actor          actor          = new Actor();
            ModernStyList  modernStylist  = new ModernStyList();
            AncientStylist ancientStylist = new AncientStylist();

            //给演员进行现代剧化妆
            modernStylist.MakeUp(actor);
            modernStylist.Act();
            //给演员进行古装剧化妆
            ancientStylist.MakeUp(actor);
            ancientStylist.Act();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            IComponent concreteComponent = new ConcreteComponent();
            IComponent component         = new ConcreteDecoratorA(new ConcreteDecoratorB(concreteComponent));

            component.Operation();
            Console.ReadKey();
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            // create a component with two decorators
            var component =
                new ConcreteDecoratorA(
                    new ConcreteDecoratorB(
                        new ConcreteComponent()));

            // perform the operation
            component.Operation();
        }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            var c = new ConcreteComponent();
            var a = new ConcreteDecoratorA();
            var b = new ConcreteDecoratorB();

            c.Operation();

            a.SetComponent(c);
            a.Operation();

            b.SetComponent(a);
            b.Operation();

            Console.ReadKey();
        }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            var c = new ConcreteComponent();
            var a = new ConcreteDecoratorA();
            var b = new ConcreteDecoratorB();

            c.Operation();

            a.SetComponent(c);
            a.Operation();

            b.SetComponent(a);
            b.Operation();

            Console.ReadKey();
        }