Bridge Pattern

Get an overview of the bridge design pattern.

Overview

According to the Gang of Four books, the bridge pattern is designed to “decouple an abstraction from its implementation so that the two can vary independently.”

This definition can be confusing, so let’s look at a mathematical example.

Let’s suppose that we have two sets:

  • set1 = (model1remote, model2remote): This is a set of remote models.
  • set2 = (Sony, Benq): This is a set of TVs that we need to make remotes for.

The cartesian product of these two sets is Cartesian Product= {(model1remote,Sony),(model1remote,Benq),(model2remote,Sony), (model2remote,Benq)}. This means that we’ll need each model of the remote for every single TV model. Now, imagine what happens when we increase the length of either of these sets. It will exponentially increase the size of our cartesian product. Let’s map this problem to programming.

In programming, we’ll have an abstract class for the remote, and every item in our cartesian product will be our concrete implementation of this class. Let’s look at the diagram.

Get hands-on with 1200+ tech skills courses.