creativity is that spark of electricity before an explosion.
it allows us, in a single instance to explore all possibilities without hesitation.
|
// Decorator pattern -- Structural example
|
|
using
System;namespace { // MainApp test application class MainApp { 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.Read(); } } // "Component" abstract class Component { public abstract void Operation(); } // "ConcreteComponent" class ConcreteComponent : Component { public override void Operation() { Console.WriteLine("ConcreteComponent.Operation()"); } } // "Decorator" abstract class Decorator : Component { protected Component component; public void SetComponent(Component component) { this.component = component; } public override void Operation() { if (component != null) { component.Operation(); } } } // "ConcreteDecoratorA" class ConcreteDecoratorA : Decorator { private string addedState; public override void Operation() { base.Operation(); addedState = "New State"; Console.WriteLine("ConcreteDecoratorA.Operation()"); } } // "ConcreteDecoratorB" class ConcreteDecoratorB : Decorator { public override void Operation() { base.Operation(); AddedBehavior(); Console.WriteLine("ConcreteDecoratorB.Operation()"); } void AddedBehavior() { } } } |
| [+] | Programming - Observer Behavioral Design Pattern |
| [+] | Programming - Visitor Behavioral Design Pattern |
| [+] | Microsoft releases Protocol documentation for several of its products to appease EU regulation |
| [+] | Microsoft Announces New Support for Silverlight by Content Companies Worldwide |
| [+] | Silverlight 2 on Mobile from Nokia |
| [+] | Programming - Design patterns in Software |
| [+] | .NET Enterprise provides a truly robust and scalable platform to build business applications on I.. |
| [+] | The Future of Javascript - The Creator ponders |
| [+] | Java and .NET both bring something to the Enterprise arena |
