For the complete documentation index, see llms.txt. This page is also available as Markdown.

Bridge Pattern

The Bridge Design Pattern is a structural design pattern that separates an abstraction from its implementation so that both can change independently.

It is useful when:

  • You want to avoid a huge number of subclasses

  • You want abstraction and implementation to evolve separately

  • You need runtime switching between implementations


Real Life Example

Think about a Remote Control and TV.

  • Remote = Abstraction

  • TV Brand = Implementation

A remote can work with:

  • Sony TV

  • Samsung TV

  • LG TV

Instead of creating:

  • SonyBasicRemote

  • SonyAdvancedRemote

  • SamsungBasicRemote

  • SamsungAdvancedRemote

You separate them using Bridge Pattern.


Structure

Main Parts:

  1. Abstraction

  2. Refined Abstraction

  3. Implementor

  4. Concrete Implementor


Laravel / PHP Example

Scenario

We want to send notifications through different channels:

  • Email

  • SMS

  • WhatsApp

And notification types:

  • Order Notification

  • Payment Notification

Without Bridge Pattern, classes explode.


Without Bridge Pattern

Too many classes.


With Bridge Pattern

We separate:

  • Notification Type → Abstraction

  • Sending Channel → Implementation


Step 1: Implementor Interface


Step 2: Concrete Implementations

Email Sender

SMS Sender

WhatsApp Sender


Step 3: Abstraction


Step 4: Refined Abstractions

Order Notification

Payment Notification


Step 5: Usage


Output


How Bridge Works

Here:

Part
Responsibility

Notification

Abstraction

OrderNotification

Refined Abstraction

MessageSender

Implementor

EmailSender/SmsSender

Concrete Implementor

Both sides can change independently.

You can:

  • Add new notification types

  • Add new sending channels

Without modifying existing code.


Advantages

1. Reduces Class Explosion

Instead of:

You only maintain:

  • Notification hierarchy

  • Sender hierarchy


2. Follows SOLID Principles

Especially:

  • Open/Closed Principle

  • Composition over Inheritance


3. Runtime Flexibility

You can switch implementations dynamically.


Another Simple Example

Device + Remote


Remote Abstraction


Usage


When to Use Bridge Pattern

Use Bridge Pattern when:

✅ Multiple dimensions vary independently ✅ You want composition over inheritance ✅ You want runtime implementation switching ✅ Too many subclasses are being created


Bridge vs Strategy

Bridge
Strategy

Separates abstraction from implementation

Encapsulates algorithm

Structural Pattern

Behavioral Pattern

Focus on scalability

Focus on behavior switching


Short Interview Definition

The Bridge Pattern separates abstraction from implementation so both can vary independently using composition instead of inheritance.

Last updated