Exemple #1
0
        private static void DemonstrateDecorator()
        {
            // First create a component that should be decorated
            var component = new ConcreteComponent();

            // Then create a decorator and supply the component to it, this expands the components functionality.
            var decoratorA = new ConcreteDecoratorA(component);

            // The pattern allows both adding the base component, or another decorator.
            var decoratorB1 = new ConcreteDecoratorB(component);
            var decoratorB2 = new ConcreteDecoratorB(decoratorA); // Expands the functionality even more.

            component.Operation();
            decoratorA.Operation();
            decoratorB1.Operation();
            decoratorB2.Operation();
            decoratorB2.AddedBehavior();
        }