-
Notifications
You must be signed in to change notification settings - Fork 10
Bridge Design Pattern
Here we are going to learn about Bridge pattern, it is structural design pattern.
Bridge is used where we need to decouple an abstraction from its implementation so that the two can vary independently. This type of design pattern comes under structural pattern as this pattern decouples implementation class and abstract class by providing a bridge structure between them. This pattern involves an interface which acts as a bridge which makes the functionality of concrete classes independent from interface implementer classes. Both types of classes can be altered structurally without affecting each other.
When there are inheritance hierarchies creating concrete implementation, you loose flexibility because of interdependence.Decouple implementation from interface and hiding implementation details from client is the essense of bridge design pattern
- Abstraction – core of the bridge design pattern and defines the crux. Contains a reference to the implementer.
- Refined Abstraction – Extends the abstraction takes the finer detail one level below. Hides the finer elements from implemetors.
- Implementer – This interface is the higer level than abstraction. Just defines the basic operations.
- Concrete Implementation – Implements the above implementer by providing concrete implementation.
Example included in Java project.
The adapter design pattern helps it two incompatible classes to work together. But, bridge design pattern decouples the abstraction and implementation by creating two different hierarchies.