示例#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)
        {
            Console.Write("Decorator Pattern\n");
            IComponent component = new Component();

            Display("1. Basic Component: ", component);
            Display("2. A-decorated: ", new DecoratorA(component));
            Display("3. B-decorated: ", new DecoratorB(component));
            Display("4. B-A-decorated: ", new DecoratorB(new DecoratorA(component)));
            var b = new DecoratorB(new Component());

            Display("5. A-B-decorated: ", new DecoratorA(b));
            Console.WriteLine(("\t\t\t" + b.addedState + b.AddedBehavior()));
            Console.ReadLine();
        }
示例#3
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();
        }
示例#4
0
        static void Main()
        {
            Console.WriteLine("Decorator pattern!\n");
            var component = new Component();

            Display("1. Basic component: ", component);
            Display("2. A-decorated: ", new DecoratorA(component));
            Display("3. B-decorated: ", new DecoratorB(component));
            Display("4. B-A-decorated: ", new DecoratorB(new DecoratorA(component)));

            //Explicit Decorator B
            var decoratorB = new DecoratorB(new Component());

            Display("5. A-B-decorated: ", new DecoratorA(decoratorB));

            //Invoking its added state and added behaviour
            Console.WriteLine("\t\t\t" + decoratorB.AddedState + decoratorB.AddedBehaviour());
        }
示例#5
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();
        }
示例#6
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();
        }