Definition
Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.(extend method, behavior of class)
UML Class Diagram
Decorator: when and where use it
- The intent of the Decorator design pattern is to let you extend an object?s behavior dynamically. This ability to dynamically attach new behavior to objects is done by a Decorator class that „wraps itself? around the original class.
- The Decorator pattern combines polymorphism with delegation. It is polymorphic with the original class so that clients can invoke it just like the original class. In most cases, method calls are delegated to the original class and then the results are acted upon, or decorated, with additional functionality. Decoration is a flexible technique because it takes place at runtime, as opposed to inheritance which take place at compile time.
Sample
- Component abstract class
- Component concrete class
- Decorate abstract class
- Decorate concrete class
- Main class
Ref: Gang of Four tutorial
7/30/2011
Design Pattern - Bridge
Definition
Decouple an abstraction from its implementation so that the two can vary independently. (Separate implementation of methods to other classes)
UML Class Diagram
Bridge: when and where use it
- The Bridge pattern is used for decoupling an abstraction from its implementation so that the two can vary independently. Bridge is a high-level architectural patterns and its main goal is through abstraction to help .NET developers write better code. A Bridge pattern is created by moving a set of abstract operations to an interface so that both the client and the service can vary independently. The abstraction decouples the client, the interface, and the implementation.
- A classic example of the Bridge pattern is when coding against device drivers. A driver is an object that independently operates a computer system or external hardware device. It is important to realize that the client application is the abstraction. Interestingly enough, each driver instance is an implementation of the Adapter pattern. The overall system, the application together with the drivers, represents an instance of a Bridge.
Sample
- Implementor interface.
- Concrete Implementor class
- Abstraction class (implementor is a part of abstraction class)
- Refined Abstraction class (concrete class of abstraction class)
- Invoke class
Ref: Gang of Four tutorial
Decouple an abstraction from its implementation so that the two can vary independently. (Separate implementation of methods to other classes)
UML Class Diagram
Bridge: when and where use it
- The Bridge pattern is used for decoupling an abstraction from its implementation so that the two can vary independently. Bridge is a high-level architectural patterns and its main goal is through abstraction to help .NET developers write better code. A Bridge pattern is created by moving a set of abstract operations to an interface so that both the client and the service can vary independently. The abstraction decouples the client, the interface, and the implementation.
- A classic example of the Bridge pattern is when coding against device drivers. A driver is an object that independently operates a computer system or external hardware device. It is important to realize that the client application is the abstraction. Interestingly enough, each driver instance is an implementation of the Adapter pattern. The overall system, the application together with the drivers, represents an instance of a Bridge.
Sample
- Implementor interface.
- Concrete Implementor class
- Abstraction class (implementor is a part of abstraction class)
- Refined Abstraction class (concrete class of abstraction class)
- Invoke class
Ref: Gang of Four tutorial
Subscribe to:
Posts (Atom)