VOOZH about

URL: https://www.geeksforgeeks.org/python/bridge-method-python-design-patterns/

⇱ Bridge Method - Python Design Patterns - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bridge Method - Python Design Patterns

Last Updated : 12 Jul, 2025

The bridge method is a Structural Design Pattern that allows us to separate the Implementation Specific Abstractions and Implementation Independent Abstractions from each other and can be developed considering as single entities.
The bridge Method is always considered as one of the best methods to organize the class hierarchy.

👁 Bridge-Method
Bridge Method

Elements of Bridge Design Pattern

  • Abstraction: It is the core of the Bridge Design Pattern and it provides the reference to the implementer.
  • Refined Abstraction: It extends the abstraction to a new level where it takes the finer details one level above and hides the finer element from the implementers.
  • Implementer: It defines the interface for implementation classes. This interface does not need to correspond directly to the abstraction interface and can be very different.
  • Concrete Implementation: Through the concrete implementation, it implements the above implementer.

Problem without using Bridge Method

Consider the following class Cuboid which has three attributes named length, breadth, and height and three methods named ProducewithAPI1(), ProduceWithAPI2(), and expand()
Out of these, producing methods are implementation-specific as we have two production APIs, and one method i.e., expand() method is implementation-independent. 

Till now we have only two implementation-specific methods and one implementation-independent method but when the quantity will rise (of course in a large-scale project) things will become messy for the developers to handle.

👁 Problem-Bridge-Method
Problem-Bridge-Method


Note: Following code is written without using the Bridge method.

Solution using Bridge method

Now let's look at the solution for the above problem. The bridge Method is one of the best solutions for such kinds of problems. Our main purpose is to separate the codes of implementation-specific abstractions and implementation-independent abstractions.

👁 Solution-Bridge-method
Solution-Bridge-Method


Note: Following Code is written using Bridge Method

UML Diagram of Bridge Method

Following is the UML diagram for Bridge Method

👁 UML-Diagram-bridge-Method
UML -diagram-Bridge-Method

Advantages

  • Single Responsibility Principle: The bridge method clearly follows the Single Responsibility principle as it decouples an abstraction from its implementation so that the two can vary independently.
  • Open/Closed Principle: It does not violate the Open/Closed principle because at any time we can introduce the new abstractions and implementations independently from each other
  • Platform independent feature: Bridge Method can be easily used for implementing the platform-independent features.

Disadvantages

  • Complexity: Our code might become complex after applying the Bridge method because we are intruding on new abstraction classes and interfaces.
  • Double Indirection: The bridge method might have a slight negative impact on the performance because the abstraction needs to pass messages along with the implementation for the operation to get executed.
  • Interfaces with only a single implementation: If we have only limited interfaces, then it doesn't sweat a breath but if you have an exploded set of interfaces with minimal or only one implementation it becomes hard to manage

Applicability

  • Run-time Binding: Generally Bridge method is used to provide the run-time binding of the implementation, here run-time binding refers to what we can call a method at run-time instead of compile-time.
  • Mapping classes: The bridge method is used to map the orthogonal class hierarchies
  • UI Environment: A real-life application of the Bridge method is used in the definition of shapes in a UI Environment


Further read: Bridge Method in Java

Comment
Article Tags: