コード例 #1
0
        private void DemoDecorator()
        {
            // Concrete
            IComponent component = new ConcreteComponent();

            Console.WriteLine(component.DoSomething("peter"));

            IComponent comp2 = new Decorator1(component);

            Console.WriteLine(comp2.DoSomething("peter"));

            IComponent comp3 = new Decorator1(comp2);

            Console.WriteLine(comp3.DoSomething("peter"));
        }
コード例 #2
0
        private void DemoDecorator()
        {
            // konkrete
            IComponent component = new ConcreteComponent();

            Console.WriteLine(component.DoSomething("peter"));

            // decorerer med Hr
            IComponent comp2 = new DecoratorKlasse(component);

            Console.WriteLine(comp2.DoSomething("peter"));


            // Decorerer med Levinsky
            IComponent comp3a = new DecoratorKlasse2(component);

            Console.WriteLine(comp3a.DoSomething("peter"));

            IComponent comp3b = new DecoratorKlasse2(comp2);

            Console.WriteLine(comp3b.DoSomething("peter"));
        }