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.

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

7s there a relation-<br />

ship between the<br />

patterns?<br />

Are the patterns<br />

interrelated?<br />

As someone new to patterns, I may not see any pattern that is obviously<br />

dependent on another pattern, nor any pattern that sets the<br />

context for all others.<br />

When there is not an obvious choice, I have to work through the<br />

combination of patterns systematically looking for the following:<br />

• Does one pattern define how the other pattern behaves?<br />

• Do two patterns mutually influence each other?<br />

The Adapter pattern is about modifying the interface of a class into<br />

another interface that the client is expecting. In this case, the interface<br />

that needs adapting is the OOGFeature. The Bridge pattern is<br />

about separating multiple concrete examples of an abstraction from<br />

their implementation. In this case, the abstraction is Feature and<br />

the implementations are the V1 and V2 systems. It sounds like the<br />

Bridge will need the Adapter to modify OOGFeature's interface,<br />

that is, the Bridge will use the Adapter.<br />

Clearly there is some relationship between Bridge and Adapter.<br />

Can I define one of the patterns without another, or is one of the<br />

patterns needed by another?<br />

Looking at the patterns tells us what to do.<br />

• I can talk about the Bridge pattern as separating the Features<br />

from the V1 and V2 systems without actually knowing how I<br />

will use the V1 and V2 systems.<br />

• However, I cannot talk about using an Adapter pattern to mod<br />

ify the V2 system's interface without knowing what it will be<br />

modified into. Without the Bridge pattern, this interface doesn't<br />

exist. The Adapter pattern exists to modify the V2 system's<br />

interface to the implementation interface the Bridge pattern<br />

defines.

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

Saved successfully!

Ooh no, something went wrong!