示例#1
0
        static void Main(string[] args)
        {
            Component c  = new ComponentA();
            Decorator d1 = new DecoratorA();
            Decorator d2 = new DecoratorB();

            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            IComponent componentX_WithNoDecorator = new ComponentX();

            componentX_WithNoDecorator.MethodA();

            IComponent componetX_WithDecoratorA = new DecoratorA(componentX_WithNoDecorator);

            componetX_WithDecoratorA.MethodA();

            IComponent componentX_WithDecoratorA_And_DecoratorB = new DecoratorB(componetX_WithDecoratorA, new DataService(), 4);

            Console.WriteLine(componentX_WithDecoratorA_And_DecoratorB.MethodB());
            Console.ReadLine();
        }
示例#3
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Decorator Pattern\n");

            IComponent component = new Component();

            Client.Display("1. Basic component: ", component);
            IComponent component1 = new DecoratorA(component);

            Client.Display("2. A-decorated : ", component1);
            Client.Display("3. B-decorated : ", new DecoratorB(component));
            Client.Display("4. B-A-decorated : ", new DecoratorB(new DecoratorA(component)));
            // Explicit DecoratorB
            var b = new DecoratorB(new Component());

            Client.Display("5. A-B-decorated : ", new DecoratorA(b));
            // Invoking its added state and added behavior
            Console.WriteLine("\t\t\t" + b.addedState + b.AddedBehavior());
            Console.ReadLine();
        }
示例#4
0
        static void Main(string[] args)
        {
            Component c = new ComponentA();
            Decorator d1 = new DecoratorA();
            Decorator d2 = new DecoratorB();
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();

            Console.ReadKey();
        }