Course Content
Data Structures & Algorithms
Full Stack Web Development
Understanding and playing with DOM (Document Object Model)
0/2
MERN project
0/2
Low Level System Design
LLD Topics
High Level System Design
Fast-Track to Full Spectrum Software Engineering
Bridge 

The Bridge Pattern is a design pattern that decouples an abstraction from its implementation so that the two can vary independently. This means you can change the abstraction and its implementation separately without affecting each other.



Understanding the Need

In software design, sometimes classes grow too large and complicated due to having multiple layers of responsibilities. For example, if you are designing a system with various shapes (like circles, rectangles) and multiple drawing APIs (like OpenGL, DirectX), directly linking them creates a combinatorial explosion of classes: CircleWithOpenGL, CircleWithDirectX, RectangleWithOpenGL, etc.

 

This is where the Bridge Pattern comes in—it splits the large class or tightly coupled classes into two separate hierarchies:

 

  • One for abstraction (e.g., shape)
  • One for implementation (e.g., drawing mechanism)

 

These hierarchies are “bridged” together by composition, not inheritance.



Real-World Analogy

Imagine a remote control (abstraction) and a TV (implementation).

 

  • You might have different remotes: basic, smart, voice-enabled.
  • You might have different TVs: Sony, LG, Samsung.

 

Using the Bridge Pattern, you can mix and match remotes with TVs. You don’t need to create a class for every remote-TV combination. Instead, you separate them and connect via a bridge.



Key Concepts

  • Abstraction – The high-level control (e.g., Shape, Remote).
  • Implementor – The low-level implementation (e.g., Drawing API, TV brand).
  • Bridge (Composition) – The abstraction holds a reference to the implementor and delegates the work.


Advantages of the Bridge Pattern

  • Reduces class explosion – Avoids a large number of subclasses for every combination.
  • Promotes flexibility – You can change either abstraction or implementation independently.
  • Supports open/closed principle – Easily extend the system without modifying existing code.
  • Better separation of concerns – Responsibilities are cleanly divided.


Use Cases of the Bridge Pattern

  • UI Toolkits – Widgets and operating system rendering engines.
  • Multimedia players – Abstracting media controls from actual playback engines.
  • Database drivers – Connecting different database interfaces to a common abstraction.
  • Hardware interface layers – Allowing operating systems to interact with different hardware using the same interface.


Limitations

  • Increased complexity – Requires planning and introduces additional layers.
  • May seem unnecessary – In simple scenarios, the added abstraction might be overkill.


Summary

The Bridge Pattern helps manage complexity by separating abstraction from implementation, making systems easier to scale and maintain. It is especially helpful in scenarios where you foresee the need to extend both sides (abstraction and implementation) independently.

0% Complete
WhatsApp Icon

Hi Instagram Fam!
Get a FREE Cheat Sheet on System Design.

Hi LinkedIn Fam!
Get a FREE Cheat Sheet on System Design

Loved Our YouTube Videos? Get a FREE Cheat Sheet on System Design.