Example #1
0
        static void Main(string[] args)
        {
            IComponent component = new ConcreteComponent();

            component = new ConcreteComponentDecoratorA(component);
            component = new ConcreteComponentDecoratorB(component);
            var result = component.Get();

            Console.WriteLine(result);
        }
Example #2
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        public void Execute()
        {
            // Create ConcreteComponent and two Decorators
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            // Link decorators
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();
        }
Example #3
0
        public void Run()
        {
            // Create ConcreteComponent and two Decorators
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            d1.Component = c;
            d2.Component = d1;
            d2.Operation();

            // Wait for user
            Console.ReadKey();
        }
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        private static void Main()
        {
            // Create ConcreteComponent and two Decorators
              ConcreteComponent c = new ConcreteComponent();
              ConcreteDecoratorA d1 = new ConcreteDecoratorA();
              ConcreteDecoratorB d2 = new ConcreteDecoratorB();

              // Link decorators
              d1.SetComponent(c);
              d2.SetComponent(d1);

              d2.Operation();

              // Wait for user
              Console.ReadKey();
        }
Example #5
0
        public void Test()
        {
            var component = new ConcreteComponent();

            var decoratorA = new ConcreteDecoratorA {
                Component = component
            };

            decoratorA.Operation();

            var decoratorB = new ConcreteDecoratorB {
                Component = component
            };

            decoratorB.Operation();
        }
Example #6
0
        /// <summary>
        /// Entry point into console application.
        /// </summary>
        private static void Main()
        {
            // Create ConcreteComponent and two Decorators
            ConcreteComponent  c  = new ConcreteComponent();
            ConcreteDecoratorA d1 = new ConcreteDecoratorA();
            ConcreteDecoratorB d2 = new ConcreteDecoratorB();

            // Link decorators
            d1.SetComponent(c);
            d2.SetComponent(d1);

            d2.Operation();

            // Wait for user
            Console.ReadKey();
        }
Example #7
0
        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);
        }