Design Pattern Download: The Bridge Pattern

The Bridge pattern is a Structural Pattern used in software engineering when you want to divide orthogonal components of a system so that they can be iterated on independently.

Example

We want to create some software that integrates with a phone. We want to be able to separate the device itself from the OS so that we can logically compartmentalize the two independent items. This way we can build out one section on one team while another team works on the other.

When to use the Bridge?

  • When we want to divide a bloated class into several independent components
  • When we want to further extend individual components (i.e. we want to create functionality only for a specific version of ios)

What is the Bridge Pattern composed of?

  • The Abstractions (one abstract class which will contain the other abstractions and interfaces for the other orthogonal components)
  • The Implementations (the classes implementing these abstractions)

Implementation

The Abstractions

The interface is for the OSSystem and the abstract class is for the Device the only reason the Device needs to be abstract is because it needs to have a link (a bridge) to the other components in the form of instance variables.

The Implementations

OSSystems

Devices

Here we create the implementations

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store