Difference between revisions of "Bridge"

From CDOT Wiki
Jump to: navigation, search
(Implementation)
(Consequences)
Line 45: Line 45:
 
<li>Improved extensibility</li>
 
<li>Improved extensibility</li>
 
<li>Hiding implementation detail from clients</li>
 
<li>Hiding implementation detail from clients</li>
 +
<li>Reduction in the number of sub classes</li>
 +
<li>Cleaner code and Reduction in executable size</li>
 +
<li>Interface and implementation can be varied independently</li>
 +
<li>Lossely coupled client code</li>
 
</ul>
 
</ul>
  

Revision as of 18:48, 1 March 2007

Introduction

The bridge pattern is a design pattern used in software developing, decouple an abstraction from its implementation so that the two can vary independently. It is also known as Handle or Body.

UML Structure

Applicability

The Bridge pattern is applicable when:

  • we want to avoid a permanent binding between an abstraction and its implementation
  • both the abstractions and their implementations should be extensible by subclassing
  • changes in the implementation of an abstraction should have no impact on clients
  • we want to hide the implementation of an abstraction completely from clients
  • we want to share an implementation among multiple objects, and this fact should be hiddent from the client

Participants

The classes and/or objects participating in this pattern are:

  • Abstraction
    • defines the abstraction's interface
    • maintains a reference to an object of type Implementor
  • Refined Abstraction
    • extends the interface defined by Abstraction.
  • Implementor
    • defines the interface for implementation classes. This interface does not have to correspond exactly to Abstraction's interface; in fact the two interfaces can be quite different. The Implementation interface provides only primitive operations, and Abstraction defines high-level operations based on these primitives.
  • Concrete Implementor
    • implements the Implementor interface and defines its concrete implementation.

Collaborations

Consequences

The Bridge pattern has the following consequence:

  • Decoupling interface and implementation
  • Improved extensibility
  • Hiding implementation detail from clients
  • Reduction in the number of sub classes
  • Cleaner code and Reduction in executable size
  • Interface and implementation can be varied independently
  • Lossely coupled client code

Implementation

When applying the Bridge pattern, consider the following implementation issues:

  • Only one Implementor
  • Creating the right Implementor object
  • Sharing implementors
  • Using multiple inheritance

Code Examples

Related Patterns

Abstract Factory Adapter

References

Other