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.

Chapter 21 • <strong>Design</strong> <strong>Patterns</strong> Reviewed 3O7<br />

The value of hiding the implementations is that the patterns allow<br />

for easily adding new implementations, since the client objects do<br />

not know how the current implementation works.<br />

Commonality/Variability Analysis and<br />

<strong>Design</strong> <strong>Patterns</strong><br />

In Chapter 9, "The Bridge Pattern," I showed how the Bridge pattern<br />

can be derived using commonality/variability analysis. Many other<br />

patterns can be derived as well, including the Strategy, Iterator,<br />

Proxy, State, Visitor, Template Method, and Abstract Factory. What<br />

is more important, however, is how many patterns are imple mented<br />

by using commonality/variability analysis. Looking for<br />

commonalities can help us discover that a pattern is present in our<br />

problem domain.<br />

For example, in the Bridge pattern, I may start with several special<br />

cases:<br />

• Draw a square with drawing program one.<br />

• Draw a circle with drawing program two.<br />

• Draw a rectangle with drawing program one.<br />

Knowing the Bridge helps me see these as special cases of two commonalities:<br />

• Drawing programs<br />

• Shapes to draw<br />

The Strategy pattern is similar in that when I see several different<br />

rules, I know to look for a commonality amongst the rules so I can<br />

encapsulate them.<br />

Commonality/<br />

variability analysis

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

Saved successfully!

Ooh no, something went wrong!