Yes, the goal of the Patter bridge is to separate the abstraction (i.e. the interface) from the implementation so that they change independently. In practice, the idea is to use two separate hierarchies instead of a classic single hierarchy.
Make an example. Suppose you have an abstraction of Window, and you need to create a subclass of IconWindow that specializes Window for each supported platform.
With a single hierarchy, you get:
Window |--------------... IconWindow | -----------------------------------------------... | | | XIconWindow MSIconWindow OSXIconWindow
This structure is very inconvenient because:
if you want to add a new subclass that specializes in Window (e.g. BitmapWindow), you must create a subclass for each supported platform (i.e. three subclasses in this example).
If you want to add a supported platform, you must add a new subclass for each existing specialization.
Therefore, it is better to separate the two hierarchies with:
imp Window--------------------------> WindowImp | | -----------.... --------------------------------- | | | | IconWindow XWindowImp MSWindowImp OSXWindowImp
Window and WindowImp are interfaces. IconWindow uses the methods provided by Window. The window, in turn, calls the associated method on imp.
The relationship between Window and WindowImp is called Bridge .
Example: IconWindow :: DrawBorder () uses Window :: DrawRect (), which calls imp-> DevDrawLine (), which is declared in WindowImp and defined in specific subclasses (for example, in the XWindowImp class).
My suggestion is to read the book: Design Patterns - Elements of Reusable Object-Oriented Software "( http://en.wikipedia.org/wiki/Design_Patterns ), which contains the example above.
Claudio
source share