šŸ“… Week-5 (Day-5) - Exploring Real-World Applications and Code Examples of the Bridge Design Pattern

Payal KumariPayal Kumari
4 min read

NOTE: - I started my 8-week system design journey with Coder Army. I will be journaling every day, recording what I learn, reflecting on it, and sharing it with my network to help newcomers to system design.

šŸ’  What is the Bridge Design Pattern?

Definition: Bridge Pattern decouples an abstraction from its implementation so that both can vary independently.

(Hindi: Bridge Pattern ek abstraction ko uske implementation se alag karta hai taaki dono apne-apne tareeke se badal sakein, bina ek doosre ko impact kiye.)

šŸ’ The Problem It Solves

When you mix different types of features in one place — like Car types (SUV, Sedan) and Engines (Diesel, Petrol, Electric) — you end up with too many subclasses. Every combination leads to a new class:

SUV + Petrol => SUVPetrol SUV + Diesel => SUVDiesel Sedan + Petrol => SedanPetrol ... and so on

This is called Class Explosion

  • Difficult to maintain

  • Poor code reuse

  • Complex relationships

(Hindi: Har naye combination ke liye ek naye class banani padti hai — isse system complex ho jaata hai aur maintain karna mushkil.)

šŸ’ Bridge Pattern to the Rescue

With Bridge Pattern:

  • Abstractions like Car are separate from implementations like Engine

  • You can mix and match them at runtime without creating a new class for each combo

šŸ’ Separation Example:

  • Abstraction Layer āž”ļø Car (Sedan, SUV)

  • Implementation Layer āž”ļø Engine (Petrol, Diesel, Electric)

(Hindi: Car aur Engine alag layers me honge — Car sirf ek abstraction hogi aur Engine ek implementation.)

šŸ’ Real-World Examples

1ļøāƒ£ Remote Control

  • Abstraction: Remote (BasicRemote, AdvancedRemote)

  • Implementation: Devices (TV, Radio, AC)

2ļøāƒ£ UI Elements on OS

  • Abstraction: UI Components (Dropdown, Button)

  • Implementation: OS (Windows, Linux, macOS)

šŸ’  When to Use Bridge Pattern?

āœ… When you need independent variations of abstraction and implementation

āœ… When there’s risk of class explosion

āœ… When you want clean separation of concerns

šŸ“š Benefits

  • Promotes code reuse

  • Keeps abstractions flexible

  • Encourages clean separation

  • Supports Open/Closed Principle (OCP)

(Hindi: Bridge pattern code ko reuseable, flexible, aur maintainable banata hai. Dono hierarchy apne hisaab se badal sakti hai.)

The Bridge Pattern helps us build large, scalable systems where combinations can change — without rewriting the entire architecture. Perfect for multi-platform UI, payment gateways, devices, or anything with "mix-and-match" behavior!


// Implementation Hierarchy: Engine interface (LLL)
interface Engine {
    void start();
}

// Concrete Implementors (LLL)
class PetrolEngine implements Engine {
    @Override
    public void start() {
        System.out.println("Petrol engine starting with ignition!");
    }
}

class DieselEngine implements Engine {
    @Override
    public void start() {
        System.out.println("Diesel engine roaring to life!");
    }
}

class ElectricEngine implements Engine {
    @Override
    public void start() {
        System.out.println("Electric engine powering up silently!");
    }
}

// Abstraction Hierarchy: Car (HLL)
abstract class Car {
    protected Engine engine;
    public Car(Engine e) {
        this.engine = e;
    }
    public abstract void drive();
}

// Refined Abstraction: Sedan
class Sedan extends Car {
    public Sedan(Engine e) {
        super(e);
    }

    @Override
    public void drive() {
        engine.start();
        System.out.println("Driving a Sedan on the highway.");
    }
}

// Refined Abstraction: SUV
class SUV extends Car {
    public SUV(Engine e) {
        super(e);
    }

    @Override
    public void drive() {
        engine.start();
        System.out.println("Driving an SUV off-road.");
    }
}

public class BridgePattern {
    public static void main(String[] args) {
        // Create Engine implementations
        Engine petrolEng = new PetrolEngine();
        Engine dieselEng = new DieselEngine();
        Engine electricEng = new ElectricEngine();

        // Create Car abstractions, injecting Engine implementations
        Car mySedan = new Sedan(petrolEng);
        Car mySUV = new SUV(electricEng);
        Car yourSUV = new SUV(dieselEng);

        // Use the cars
        mySedan.drive();   // Petrol engine + Sedan
        mySUV.drive();     // Electric engine + SUV
        yourSUV.drive();   // Diesel engine + SUV

        // No explicit cleanup needed in Java
    }
}

Week - 5 (Day-5) Completed āœ… System Design

NOTE : - A big thanks to my mentors Rohit Negi Sir and Aditya Sir for launching this amazing 8-week course absolutely free on YouTube via CoderArmy9 :- youtube.com/@CoderArmy9 . šŸ™Œ

šŸ‘‰ Share this blog with your connections! Let’s keep learning, growing, and supporting one another on this journey. šŸš€

āœļø Payal Kumari šŸ‘©ā€šŸ’»

Jai Hind šŸ‡®šŸ‡³ | #CoderArmy #LearningInPublic #SystemDesign #TechForAll #MentorshipMatters #8weeksLLdChallenge #LowLevelDesign #LLD šŸ‘©ā€šŸ’»

0
Subscribe to my newsletter

Read articles from Payal Kumari directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Payal Kumari
Payal Kumari

I'm a passionate full-stack developer with a strong foundation in the MERN stack—building and maintaining scalable web applications using React.js, Node.js, and Next.js. My journey in open source began with Hacktoberfest 2023, where I made four impactful pull requests that sparked a love for collaborative coding, global learning, and open knowledge sharing. Since then, I’ve contributed to and mentored projects in top open source programs like GSSoC’24, SSOC’24, and C4GT’24. As a Google Gen AI Exchange Hackathon ’24 Finalist and Google’s Women Techmakers (WTM) Ambassador, I’ve been privileged to support diverse communities in building meaningful tech solutions. My work as a Top 50 Mentor for GSSoC ’24 reflects my commitment to nurturing new talent in tech. Beyond development, I serve as a Student Career Guide, Profile Building Expert & Evangelist at Topmate.io, where I conduct workshops, guide students through resume building and career strategy, and help mentees navigate open source and tech careers. Recognized among the Top 5% of mentors and featured on ā€œTopmate Discover,ā€ I take pride in making mentorship accessible and impactful. My technical voice has also been acknowledged by LinkedIn, where I’ve earned the Top Voice badge seven times in domains like web development, programming, and software engineering. In addition, I hold LinkedIn Golden Badges for Research Skills, Interpersonal Skills, Critical Thinking, and Teamwork—signaling a well-rounded approach to both individual contribution and team collaboration. Graduating with an MCA from Chandigarh University in 2023, I’ve continued to fuel my curiosity by writing technical articles and sharing practical MERN stack insights across platforms. Whether it’s building polished UIs, optimizing backend performance, or guiding a mentee through their first pull request, I’m driven by the power of community and continuous learning. Let’s connect! I'm open to collaborations, mentorship, or building something impactful together. Reach out to me at kumaripayal7488@gmail.com or visit my profile on Topmate.io.