Bridge Pattern


OOAD is all about separating the abstraction from implementation. The Bridge Pattern takes this a step forward.

It encapsulates an implementation class inside of an interface class. The bridge pattern allows the Abstraction and the Implementation to be developed independently. The client code needs to access only the Abstraction - without being concerned about the Implementation. The abstraction is an interface or abstract class and the implementor is also an interface or abstract class.

The abstraction contains a reference to the implementor. Children of the abstraction are referred to as refined abstractions, and children of the implementor are concrete implementors. Since we can change the reference to the implementor in the abstraction, we are able to change the abstraction's implementor at run-time. Changes to the implementor do not affect client code.

The Bridge Pattern has four participants:

  • Abstraction: The core of the bridge design pattern and defines the crux. Contains a reference to the implementer.
  • Refined Abstraction: It extends the abstraction takes the finer detail one level below. Hides the finer elements from implemetors.
  • 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. Abstraction imp provides an implementation in terms of operations provided by Implementer interface.
  • Concrete Implementation: Implements the above implementer by providing concrete implementation.