Design Patterns: Structural Pattern - Bridge
Design Patterns: Structural Pattern - Bridge
Intent:
Decouple an abstraction from its implementation so
that the two can vary independently
Also Known As:
Handle/Body
Motivation:
When an abstraction can have one of several
implementations, the usual way to accommodate them
is to use inheritance. An abstract class defines the
interface to the abstraction, and concrete subclasses
implement it in different ways.
Applicability:
Use Bridge pattern when
- You want to avoid a permanent binding between an
abstraction and its implementation. This might be the case, for
example, when the implementation must be selected or
switched at run-time.
- Both the abstractions and their implementations should be
extensible by sub-classing. In this case, the BRIDGE pattern lets
you combine the different abstractions and implementations
and extend them independently.
- Changes in the implementation of an abstraction should have
no impact on clients; that is, their code should not have to be
compiled.
Window
drawText()
drawRect()
devDrawText()
devDrawLine()
XIconWindow PMIconWindow
Window <<Interface>>
WindowImp
drawText()
drawRect() devDrawText()
devDrawText() devDrawLine()
devDrawLine()
XWindowImp PMWindowIMP
IconWindow TransientWindow
devDrawText() devDrawLine()
drawBorder() drawCloseBox()
devDrawLine() devDrawText()
Q&A