23.07.2012 Views

Design Patterns Explained

Design Patterns Explained

Design Patterns Explained

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

Start with the<br />

canonical form<br />

.. . and map classes<br />

into it<br />

Figure 12-6 Using inheritance to handle the two model types.<br />

Figure 12-7 Using the Bridge pattern to handle the two model types.<br />

Note that I do not really have a Bridge pattern in Figure 12-7<br />

because Model is not varying except for the implementation. In the<br />

Feature, I have different types of Features that have different<br />

types of implementations— a Bridge pattern does exist here.<br />

I start implementing the Bridge pattern by using Feature as the<br />

abstraction and using V1 and V2 as the basis for the implementations.<br />

To translate the problem into the Bridge pattern, I start with<br />

the standard example of the Bridge pattern and then substitute<br />

classes into it. Figure 12-8 shows the standardized, simplified form<br />

(sometimes called the canonical form).<br />

In the problem, Feature maps to Abstraction. There are five dif -<br />

ferent kinds of features: slot, hole, cutout, irregular, and special.<br />

The implementations are the V1 and V2 systems; I choose to name<br />

the classes responsible for these implementations viimp and<br />

V2lmp, respectively.

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

Saved successfully!

Ooh no, something went wrong!