Bridge pattern

related topics
{math, number, function}
{@card@, make, design}
{math, energy, light}
{system, computer, user}
{school, student, university}
{work, book, publish}
{car, race, vehicle}
{style, bgcolor, rowspan}
{line, north, south}

The bridge pattern is a design pattern used in software engineering which is meant to "decouple an abstraction from its implementation so that the two can vary independently" [1]. The bridge uses encapsulation, aggregation, and can use inheritance to separate responsibilities into different classes.

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 as well as what it does vary often. The class itself can be thought of as the implementation and what the class can do as the abstraction. The bridge pattern can also be thought of as two layers of abstraction.

The bridge pattern is often confused with the adapter pattern. In fact, the bridge pattern is often implemented using the class adapter pattern, e.g. in the C++ code below.

Variant: The implementation can be decoupled even more by deferring the presence of the implementation to the point where the abstraction is utilized.

Contents

Structure

Bridge UML class diagram.svg

Example

The following Java (SE 6) program illustrates the 'shape' example given above and will output:

Full article ▸

related documents
Steiner system
Subtraction
Residue theorem
Nowhere dense set
Hash collision
Weierstrass–Casorati theorem
Residue (complex analysis)
Double negative elimination
Borel-Cantelli lemma
Partial function
Commutative ring
Calculus with polynomials
Malleability (cryptography)
Atlas Autocode
GNU Octave
Subalgebra
Magma computer algebra system
Category (mathematics)
Byte-order mark
Algebraic extension
Dyadic rational
Abstract factory pattern
Stirling number
Extractor
Cayley's theorem
T1 space
Algebraic number
C*-algebra
Zeta distribution
Iteration