Featured Post

NoSQL use cases

Here are a simple summary of use cases for Cassandra, MongoDB and Redis MongoDB Storing Log Data Speed is the primary perfor...

Tuesday, April 28, 2015

Bridge Design Pattern

Bridge Design Pattern tells : decouple an Abstraction from its Implementation so that the two can vary independently.

At a first time this statement could suggest that the term Implementation refers to the concept of Concreate Class and the term Abstraction refers to a generic Interface.

Actually the concept of Implementation has nothing to do with the Subclassing concept. Implementation refers to one or more Components that an Abstraction uses to implement itself. In this way we are talking about composition, not inheritance.

The Bridge Design Pattern suggests to consider an Abstraction has a concept that may have different implementations. Therefore you should design an Implementation as an extention point: an Interface with a different class hierarchy.

As you can see from this UML Diagramm taken from Wikipedia that describes Bridge Design Pattern:

  • Abstraction is in a class hierarchy different from the Implementation hierarchy;
  • The bridge from these two hierarchies is made by Composition

The essence of the Bridge Design Pattern is in the Open-Closed Principle: open for extension, but closed for modification. You can evolve the abstraction indipendently from its "body" (the implementation). In other words you are designing the domain with this approach:

  • Identify concepts: Abstraction
  • Identify concepts that are implementation of Abstraction
  • Let an Abstraction uses Implementation to build itself

No comments :

Post a Comment