Skip to content

Bridge Design Pattern

Vishnu Garg edited this page Mar 31, 2015 · 3 revisions

Here we are going to learn about Bridge pattern, it is structural design pattern.

Introduction

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.

Problem and need of Bridge pattern

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

Elements 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.

Implementation with example.

Example included in Java project.

Bridge Vs Adapter Design Pattern

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.

Clone this wiki locally