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.

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

Pick Adapter next<br />

Taking advantage of nongeneralities to debug code.<br />

Earlier in this chapter, I mentioned that some of the methods of<br />

the implementation should only be called by certain Feature<br />

objects. I can take advantage of knowing what should be calling<br />

what to put checks in the code. I do not need to do this, and I<br />

may need to remove these checks if the rules change. Nevertheless,<br />

it can be useful the first time in.<br />

For example, in the CAD/CAM solution, there are Features<br />

containing an implementation object. One of the implementation<br />

methods is getEdgeType. This only makes sense if a Feature is a<br />

slot or a cutout. Other Features do not have edge types. If I have<br />

implemented things properly, the getEdgeType method will<br />

never get called except by slots and cutouts. I can check that this<br />

happens by using an assert in the getEdgeType method that<br />

verifies that the calling Feature is of the appropriate type.<br />

Thinking in <strong>Patterns</strong>: Step 2d (Adapter)<br />

Having applied Facade, I can now apply Adapter. This results in<br />

Figure 12-11.<br />

Figure 12-11 After applying the Bridge, Facade, and Adapter.

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

Saved successfully!

Ooh no, something went wrong!