/// <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(); }
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(); }
public void Test() { var component = new ConcreteComponent(); var decoratorA = new ConcreteDecoratorA { Component = component }; decoratorA.Operation(); var decoratorB = new ConcreteDecoratorB { Component = component }; 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); }