Jan 7, 2009

Design Patterns : Bridge

Bridge decouples the abstraction from implementation so that the two can vary independently.
Client which uses the classes inheriting the abstraction need not know about the service implementations.Bridge pattern abstracts the implementations’ interface from the application.
An example ? Consider database drivers. Removing the dependency from database vendors from the systems provides more flexibility.

Inheritance is a common way to specify different implementations of an abstraction. However, the implementations are then bound tightly to the abstraction,and it is difficult to modify them independently. The Bridge pattern provides an alternative to inheritance when there is more than one version of an abstraction.The Bridge Pattern is classified as a structural design pattern.This pattern helps to hide the implementation details giving more encapsulation.As the interface implementations and abstractions are decoupled , they can have hierarchies.Changing an implementation needn't require any compilation of abstractions or its clients.This provides a better layering structure than having the traditional abstract implementation of parent interfaces.

Sample Code:
http://bytescrolls-samples.googlecode.com/files/bridge-design.zip

More:
http://en.wikipedia.org/wiki/Bridge_pattern

No comments:

Post a Comment