Saturday, 11 January 2014

Bridge Design pattern - Introduction

Master Software Architecture & Clean Code!

Subscribe to Ram N Java for clean code, design pattern implementations, and practical Java tutorials!

SUBSCRIBE NOW

What is the Bridge Design Pattern?

The Bridge Design Pattern is a structural design pattern defined by the Gang of Four (GoF) that lets you decouple an abstraction from its implementation so that both can vary independently. In object-oriented programming, inheritance often binds classes too tightly at compile time, leading to rigid architectures and class explosion.

Instead of relying on deep class hierarchies, the Bridge pattern adopts the principle of composition over inheritance. It divides the problem into two distinct dimensions—the high-level control logic (abstraction) and the low-level platform-specific execution (implementation)—and connects them via an object reference.

The Core Problem: Class Explosion

Consider an application that manages geometric shapes (Circles, Squares) rendered across different platforms (Vector, Raster):

  • Inheritance Approach: You would need classes like VectorCircle, RasterCircle, VectorSquare, and RasterSquare. Adding one shape and one renderer requires multiplying class combinations exponentially.
  • Bridge Pattern Approach: Shapes become the abstraction hierarchy, while Renderers become the implementor interface. Adding a new shape or renderer only requires adding one standalone class.

Anatomy of the Bridge Pattern

  • Abstraction: High-level interface containing business logic and a reference to the Implementor.
  • Refined Abstraction: Extends or customizes the Abstraction for specific use cases.
  • Implementor: Declares the common primitive operations that concrete platforms or engines must provide.
  • Concrete Implementors: Platform-specific implementations of the Implementor interface.

Watch More Related Design Pattern Tutorials


Click here to watch in Youtube : https://www.youtube.com/watch?v=GPNVN4TnvMU

Click the below Image to Enlarge
Bridge Design pattern - Introduction

















See also:

  • Bridge Design pattern - Real time example [Send Message]
  • Bridge Design pattern - Real time example [Publish Message]
  • Bridge Design pattern - Real time example [Shape]
  • Bridge Design pattern - Real time example [TV]
  • Bridge Design pattern - Class Diagram
  • Bridge Design pattern - Implementation [Shape]
  • Bridge Design pattern - Implementation [Send Message]
  • Bridge Design pattern - Implementation [Publish Message]
  • Bridge Design pattern - Implementation [LED TV]
  • Bridge Design pattern - Keypoints
  • All Design Patterns Links
  • No comments:

    Post a Comment

    Tutorials