Skip to main content

What does the Bridge pattern do?

Bridge is a structural design pattern that separates an abstraction from its implementation, letting them evolve independently of each other.


1. The Core Idea

Usually an abstraction (for example, a control interface) and an implementation (a concrete work mechanism) are tightly coupled: a change in one pulls in a change in the other. Bridge removes that coupling:

  • the abstraction holds a reference to the implementation interface,
  • the implementation can be changed or swapped out without changing the abstraction.

This achieves flexibility: you can combine different abstractions with different implementations.


2. When to Apply It

  • When you need to separate high-level logic (what an object does) from low-level implementation (how it does it).
  • When the number of classes grows too large due to a combination of factors (for example, Circle + Red, Square + Blue, and so on).
  • When the implementation needs to be changed at runtime.

3. Structure

  1. Abstraction - defines the abstraction's interface and holds a reference to an Implementor object.
  2. RefinedAbstraction - a concrete version of the abstraction that uses Implementor.
  3. Implementor - the implementation interface (low-level operations).
  4. ConcreteImplementor - a concrete implementation of the interface.

4. Example (Java)

java
// Implementation interface interface Device { void turnOn(); void turnOff(); void setVolume(int level); } // Concrete implementation class TV implements Device { public void turnOn() { System.out.println("TV on"); } public void turnOff() { System.out.println("TV off"); } public void setVolume(int level) { System.out.println("TV volume " + level); } } // Abstraction abstract class Remote { protected Device device; public Remote(Device device) { this.device = device; } abstract void togglePower(); } // Refined abstraction class AdvancedRemote extends Remote { private boolean on = false; public AdvancedRemote(Device device) { super(device); } void togglePower() { if (on) device.turnOff(); else device.turnOn(); on = !on; } }

Now the implementation can be swapped easily:

java
Remote remote = new AdvancedRemote(new TV()); remote.togglePower(); // works with any device

5. Advantages

  • Independent changes: the abstraction and the implementation can evolve separately.
  • Fewer classes (instead of many combinations, two hierarchies are created).
  • The ability to swap the implementation dynamically at runtime.

6. Disadvantages

  • Complicates the architecture: an extra level of abstraction is added.
  • Requires careful interface design.

Summary: The Bridge pattern separates "what an object does" (the abstraction) from "how it does it" (the implementation), turning them into two independent, easily combinable hierarchies, which increases the system's flexibility and scalability.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.