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.

Chapter 12 • Solving the CAD/CAM Problem with <strong>Patterns</strong> 213<br />

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

(Abstract Factory)<br />

All that is left is the Abstract Factory. As it turns out, this pattern is<br />

not needed. The rationale for using an Abstract Factory was to<br />

ensure all of the implementation objects were of type V1 if I had a<br />

V1 system or of type V2 if I had a V2 system. However, the Model<br />

object itself will know this. There is no point implementing a pattern<br />

if some other object can easily encapsulate the rules of creation. I<br />

left the Abstract Factory in the set of patterns because while I was<br />

first solving this problem I did think the Abstract Factory was present.<br />

It also illustrates how thinking that a pattern is present when it is<br />

not is not necessarily counterproductive.<br />

Thinking in <strong>Patterns</strong>: Step 3<br />

The details of the design may still take some work. However, I<br />

would continue with the design by following Alexander's mandate<br />

of designing by context. For example, when I see how I need to<br />

implement a SlotFeature class or the V1Imp class, I should<br />

remember how the patterns involved are used. In this case, I note<br />

that in the Bridge pattern, the methods involving the abstractions<br />

are independent of implementation. This means that the<br />

Abstraction class (Feature) and all of its derivations<br />

(Slot-Feature, HoleFeature, and so forth) contain no<br />

implementation information. Implementation information is left to<br />

the Implementation classes.<br />

This means the Feature derivations will have methods such as<br />

getLocation and getLength, while the Implementations will<br />

contain a way to access this required information. A Vllmp object,<br />

for example, would need to know the ID of the Feature in the V1<br />

system. Since each Feature has a unique ID, this means there will<br />

be one Implementation object for each Feature object. The<br />

methods in the Vllmp object will use this ID to ask the VlFacade<br />

for information about the object.<br />

Finally, do Abstract<br />

Factory<br />

Finishing the rest<br />

Assigning<br />

responsibilities

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

Saved successfully!

Ooh no, something went wrong!