23.07.2012 Views

Design Patterns Explained

Design Patterns Explained

Design Patterns Explained

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

224 Part IV • Putting It All Together: Thinking in <strong>Patterns</strong><br />

Containing<br />

variation in the<br />

Facade pattern<br />

Not just about<br />

containing variation<br />

The Facade typically does not contain variation. However, I have<br />

seen many cases where a Facade was used to work with a particular<br />

subsystem. Then, when another subsystem came along, a Facade<br />

for the new subsystem was built with the same interface. This new<br />

class was a combination Facade and Adapter in that the primary<br />

motivation was simplification, but now had the added constraint of<br />

being the same as the one used before so none of the client objects<br />

would need to change. Using a Facade this way hides variations in<br />

the subsystems being used.<br />

<strong>Patterns</strong> are not just about containing variation, however. They also<br />

identify relationships between variations. I will show more about<br />

this in the next section of this book. Referring to the Bridge pattern<br />

again, note that the pattern not only defines and contains the varia -<br />

tions in the abstraction and implementation, but also defines the<br />

relationship between the two variations.<br />

Summary<br />

In this chapter In this chapter, I have shown how patterns illustrate two powerful<br />

design strategies:<br />

• <strong>Design</strong> from context<br />

• Contain variations in classes<br />

These strategies allow us to defer decisions until we can see the<br />

ramifications of these decisions. Looking at the context from which<br />

we are designing gives us better designs.<br />

By containing variation, I can accommodate future variations that<br />

may arise but would not be accommodated when I do not try to<br />

make my designs more general-purpose. This is critical for those<br />

projects that do not have all of the resources you would like to have<br />

(in other words, all projects). By containing variation appropriately,<br />

I can implement only those features I need without sacrificing

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!