Structural – Bridge Design Pattern
August 2, 2020 1 min read

Bridge Pattern is a Structural Design Pattern that lets you to separate one large class into two separate hierarchies Abstraction and Implementation that can be developed independently. It increases the loose coupling between class abstraction and its implementation.
Let’s see an example on bridge pattern in java.
Observe the bridge between “Shape” and “Colour” interfaces and use of composition in implementing the bridge pattern.

Here is the java code for “Shape” and “Colour” interfaces.
You can see inside the interface “Colour” there is a method called “apply()”. After creating the abstract class “Shape”, I made a constructor with the implementer “Colour” as the input argument. As well as I created an abstract method called “apply()” same as the method of “Colour” interface.

Here I created a class called “Circle” by extending the abstract class “Shape” and you can see the inherited constructor and the method “apply()”.

Class “Hexagon” also same as the class “Circle” as both of them are shapes.

Next I created two classes “Red” and “Blue” by implementing the interface “Colour” to override the method “apply()” for the purpose of applying colours to the shapes.
Let’s test our bridge pattern implementation with the main method.

Here is the output.

From using the bridge pattern we can hide the implementation from the client application.
You can visit the below given articles to learn about creational design patterns.
Thank you.
Creational Design Patterns


