static void Main() { // Create ConcreteComponent and 2 decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); /* * Will output: * ConcreteComponent.Operation() * ConcreteDecoratorA.Operation() * ConcreteDecoratorB.AddedBehavior() * ConcreteDecoratorB.Operation() */ }
static void Main() { // Create ConcreteComponent and 2 decorators ConcreteComponent c = new ConcreteComponent(); ConcreteDecoratorA d1 = new ConcreteDecoratorA(); ConcreteDecoratorB d2 = new ConcreteDecoratorB(); // Link decorators d1.SetComponent(c); d2.SetComponent(d1); d2.Operation(); /* Will output: ConcreteComponent.Operation() ConcreteDecoratorA.Operation() ConcreteDecoratorB.AddedBehavior() ConcreteDecoratorB.Operation() */ }