bridge - Harsh4999/Design-Patterns GitHub Wiki

Bridge

##Use

  • Using bridge pattern we can decouple the abstraction so they can both change without affecting eachother
  • We achieve it by creating 2 seperate inheritance hierarchies one for implementation and another for abstraction
  • We use composition for bridge

##UML

  • Abstraction class = defines the abstraction interface, it has refrenece to implementor
  • Refind abstraction = child of Abstraction it defines the specified abstraction
  • Implementor = Its base interface which provides methods to Abstraction, methods are unrelated to abstraction and typically represent smaller steps needed bridge is called the relationship between the Abstraction and Implementor
  • Concrete Implementors = they implement Implementor

##Implementation

  • We determine common base operations and define them in abstraction
  • We can optionally also define abstraction & provide more specialized operations
  • Implementor methods do not have to match with abstractor however abstraction can carry out its work by using implementor methods
  • We write one or more concrete implementor providing implementation
  • Abstraction are created by composiing with an instance of concrete implementor which is used by methods in abstraction
  • It reduces the dependencies and make both classes and interface indepenedent we can change any methods anywhere without worrying about errors of methods not implemented
  • It allows great flexiblity in between of abstraction and implementor
  • Eg: DriverManger of JDBC