codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Tutorials
🎭

Design Patterns

13 / 100 topics
11Introduction to Structural Patterns12Adapter Pattern13Bridge Pattern14Composite Pattern15Decorator Pattern16Facade Pattern17Flyweight Pattern18Proxy Pattern32Practical Exercises for Structural Patterns
Tutorials/Design Patterns/Bridge Pattern
🎭Design Patterns

Bridge Pattern

Updated 2026-05-15
10 min read

Bridge Pattern

Introduction

In software design, the Bridge Pattern is a structural pattern that decouples an abstraction from its implementation so that the two can vary independently. This pattern allows for greater flexibility and scalability in your codebase by separating the high-level logic (abstraction) from the low-level details (implementation).

The Bridge Pattern is particularly useful when you have multiple implementations of an interface, and you want to be able to switch between them without changing the client code that uses these implementations. This separation of concerns makes it easier to maintain and extend your system.

Concept

The Bridge Pattern involves two main components:

  1. Abstraction: This is the high-level component that defines the operations that will be used by the client.
  2. Implementor: This is the low-level component that provides the actual implementation of the abstraction's operations.

By using the Bridge Pattern, you create a bridge between these two components, allowing them to work together seamlessly while remaining independent of each other.

Key Benefits

  • Decoupling: The abstraction and implementation are decoupled, making it easier to modify or extend either component without affecting the other.
  • Flexibility: You can easily switch implementations by changing a single line of code in the client.
  • Maintainability: Changes in one part of the system do not affect the other, improving maintainability.

Examples

Let's walk through an example to illustrate how the Bridge Pattern works. We'll create a simple application that demonstrates different types of drawing tools (abstraction) with different rendering engines (implementor).

Step 1: Define the Implementor Interface

First, we define the Implementor interface that will be implemented by different rendering engines.

TypeScript
1interface DrawingImplementor {
2drawCircle(x: number, y: number, radius: number): void;
3}

Step 2: Implement Concrete Implementors

Next, we create concrete implementations of the DrawingImplementor interface for different rendering engines.

TypeScript
1class VectorDrawingImplementor implements DrawingImplementor {
2drawCircle(x: number, y: number, radius: number): void {
3 console.log(`Vector: Drawing a circle at (${x}, ${y}) with radius ${radius}`);
4}
5}
6
7class RasterDrawingImplementor implements DrawingImplementor {
8drawCircle(x: number, y: number, radius: number): void {
9 console.log(`Raster: Drawing a circle at (${x}, ${y}) with radius ${radius}`);
10}
11}

Step 3: Define the Abstraction

Now, we define the Abstraction class that will use the DrawingImplementor.

TypeScript
1class Drawing {
2protected implementor: DrawingImplementor;
3
4constructor(implementor: DrawingImplementor) {
5 this.implementor = implementor;
6}
7
8drawCircle(x: number, y: number, radius: number): void {
9 this.implementor.drawCircle(x, y, radius);
10}
11}

Step 4: Create Refined Abstractions

We can create refined abstractions that extend the Drawing class to add more specific behavior.

TypeScript
1class Circle extends Drawing {
2constructor(implementor: DrawingImplementor) {
3 super(implementor);
4}
5
6draw(): void {
7 this.drawCircle(10, 20, 5);
8}
9}

Step 5: Use the Bridge Pattern

Finally, we can use the Bridge Pattern to create different drawing tools with different rendering engines.

TypeScript
1const vectorDrawing = new Circle(new VectorDrawingImplementor());
2vectorDrawing.draw();
3
4const rasterDrawing = new Circle(new RasterDrawingImplementor());
5rasterDrawing.draw();

Output

When you run the above code, you should see the following output:

Output
Vector: Drawing a circle at (10, 20) with radius 5
Raster: Drawing a circle at (10, 20) with radius 5

What's Next?

In this tutorial, we explored the Bridge Pattern and how it can be used to decouple an abstraction from its implementation. In the next section, we will dive into another structural pattern called the Composite Pattern, which allows you to compose objects into tree structures to represent part-whole hierarchies.

Stay tuned for more insights into design patterns and how they can help you build robust and scalable software systems!


PreviousAdapter PatternNext Composite Pattern

Recommended Gear

Adapter PatternComposite Pattern