示例#1
0
        static void Main(string[] args)
        {
            Component component  = new ConcreteComponent();  //man
            Decorator decoratorA = new ConcreteDecoratorA(); //man in suit
            Decorator decoratorB = new ConcreteDecoratorB(); //man in suit in car

            component.Operation();
            decoratorA.Component = component;
            decoratorA.Operation();

            decoratorB.Component = decoratorA;
            decoratorB.Operation();
        }
        static void Main(string[] args)
        {
            Client client = new Client();

            var simple = new ConcreteComponent();

            Console.WriteLine("Client: I get a simple component:");
            client.ClientCode(simple);
            Console.WriteLine();

            // ...as well as decorated ones.
            //
            // Note how decorators can wrap not only simple components but the
            // other decorators as well.
            ConcreteDecoratorA decorator1 = new ConcreteDecoratorA(simple);
            ConcreteDecoratorB decorator2 = new ConcreteDecoratorB(decorator1);

            Console.WriteLine("Client: Now I've got a decorated component:");
            client.ClientCode(decorator2);
        }
示例#3
0
        public Client()
        {
            Program program = new Program();

            var simple = new ConcreteComponent();

            Console.WriteLine("Program: I get a simple component:");
            program.ProgramCode(simple);
            Console.WriteLine();

            // ...as well as decorated ones.
            //
            // Note how decorators can wrap not only simple components but the
            // other decorators as well.
            ConcreteDecoratorA decorator1 = new ConcreteDecoratorA(simple);
            ConcreteDecoratorB decorator2 = new ConcreteDecoratorB(decorator1);

            Console.WriteLine("Program: Now I've got a decorated component:");
            program.ProgramCode(decorator2);
        }
示例#4
0
        public void Ex1()
        {
            Client client = new Client();

            var simple = new ConcreteComponent();

            // Client: I get a simple component
            client.ClientCode(simple);
            Assert.AreEqual("RESULT: ConcreteComponent", _log.Dequeue());

            // ...as well as decorated ones.
            //
            // Note how decorators can wrap not only simple components but the
            // other decorators as well.
            ConcreteDecoratorA decorator1 = new ConcreteDecoratorA(simple);
            ConcreteDecoratorB decorator2 = new ConcreteDecoratorB(decorator1);

            // Client: Now I've got a decorated component
            client.ClientCode(decorator2);
            Assert.AreEqual("RESULT: ConcreteDecoratorB(ConcreteDecoratorA(ConcreteComponent))", _log.Dequeue());

            Assert.AreEqual(0, _log.Count);
        }