Pattern Comparison
The careful reader might have noticed that the three patterns described in this chapter seem to offer much the same service. At a high level, they are all helping to extend classes in novel ways, and they all provide alternatives to inheritance. A summary of when each pattern might be used was provided at the end of each section. Because this is also a programming book, we'll now summarize the object mechanisms the patterns use (see Table 2-2) and draw conclusions about their comparative operation. This summary is based on the UML diagrams and theory code for each of the patterns.
In each pattern, we can identify four roles, which can fall under
the headings original, new,
interface, and client. The
actual names given to these meta-roles are shown in the first three rows
of the table. Note that the Bridge pattern can work in two ways. In our
examples, we used the "Bridge-up" option. We assumed that we had one
implementation already and wanted to share its interface with other
implementations yet to be built. To do so, we needed to create an
Abstraction
that was closely
connected to the Bridge
interface. An
equally valid application for the Bridge pattern would be to have an
original abstraction in mind and to build it hand-in-hand with the
implementations (the "Bridge-down" approach).
Table 2-2. Comparison of Decorator, Proxy, and Bridge patterns
 | Decorator | Proxy | Bridge-down | Bridge-up |
---|---|---|---|---|
Original |
|
|
|
|
Interface |
|
|
|
Get C# 3.0 Design Patterns now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.