Bridge Design Pattern in Java.

By | July 5, 2020

In this post, We will talk and learn about the Bridge Design Pattern in Java.

Key Points About Bridge Design Pattern :

  • When we have interface hierarchies in interfaces as well as implementations then bridge design pattern is used to decouple the interfaces from implementation and hiding the implementation details from the client programs.
  • This design pattern mainly decouples an abstraction from its implementation so that these two can vary independently.
  • The implementation of bridge design pattern follows the notion to refer Composition over inheritance.
  • We may use the Bridge design patterns when both abstraction and implementation may have different hierarchies independently and we want to hide the implementation from the client application.

Now Let’s move towards the implementation of the Bridge Design Pattern.

Below is the complete source code:

Bridge Design Pattern

Shape.java

Color.java

Blue.java

 

Red.java

Rectangle.java

 

Square.java

 

ClientTest.java

Output of this Program:

Square drawn Color is Blue
============================================
Rectangle drawn Color is Red

 

You May Also Like:

Singleton Design Pattern in java
Prototype Pattern in Java
Factory Pattern in Java
Abstract Factory Pattern in Java
Builder Pattern in Java
Adapter Design Pattern in Java
Decorator Design Pattern in Java
Facade Design Pattern in Java
Flyweight Design Pattern in Java

That’s all about the Bridge Design Pattern in Java.
If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

Your email address will not be published. Required fields are marked *