-
As per the Gang of Four definitions, the Bridge Design Pattern “Decouples an abstraction from its implementation so that the two can vary independently“.
-
In the Bridge Design Pattern, there are 2 parts. The first part is the Abstraction and the second part is the Implementation. The Bridge Design Pattern allows both Abstraction and Implementation to be developed independently and the client code can only access the Abstraction part without being concerned about the Implementation part.
- We want to hide the implementation details from the client.
- We want the selection or switching of the implementation to be at runtime rather than design time.
- We want both the abstraction and implementation classes to be extensible by the subclasses.
- We want to avoid a tight coupling binding between an abstraction and its implementation.
- The changes in the implementation of an abstraction should have no impact on clients.
-
We have a DrawAPI interface which is acting as a bridge implementer and concrete classes RedCircle, GreenCircle implementing the DrawAPI interface. Shape is an abstract class and will use object of DrawAPI. BridgePatternDemo, our demo class will use Shape class to draw different colored circle.
-
Create bridge implementer interface.
-
Create concrete bridge implementer classes implementing the IDrawService interface.
-
Create an abstract class Shape using the IDrawService interface.
-
Create concrete class implementing the Shape interface.
-
Use the Shape and IDrawService classes to draw different colored circles.






