Bridge Pattern




When a class varies often, the features of object-oriented programming become very useful because changes to a program's code can be made easily with minimal prior knowledge about the program. The bridge pattern is useful when both the class and what it does vary often. The class itself can be thought of as the abstraction and what the class can do as the implementation. The bridge pattern can also be thought of as two layers of abstraction.

When there is only one fixed implementation, this pattern is known as the Pimpl idiom in the C++ world.

The bridge pattern is often confused with the adapter pattern. In fact, the bridge pattern is often implemented using the class adapter pattern, Variant: The implementation can be decoupled even more by deferring the presence of the implementation to the point where the abstraction is utilized.







Abstraction (abstract class)

defines the abstract interface

maintains the Implementor reference.

RefinedAbstraction (normal class)

extends the interface defined by Abstraction

Implementor (interface)

defines the interface for implementation classes#

ConcreteImplementor (normal class)

implements the Implementor interface


bridge 1