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.

Figure 1O-5 The ResFactory encapsulates the variations.<br />

Strategies for bridging analysis and design.<br />

Chapter 1O • The Abstract Factory Pattern 171<br />

Below are three key strategies involved in the Abstract Factory.<br />

Strategy Shown in the <strong>Design</strong><br />

Find what varies and<br />

encapsulate it.<br />

Favor composition over<br />

inheritance.<br />

<strong>Design</strong> to interfaces, not<br />

to implementations.<br />

The choice of which driver object to use<br />

was varying. So, I encapsulated it in<br />

ResFactory.<br />

Put this variation in a separate object—<br />

ResFactory— and have ApControl<br />

use it as opposed to having two different<br />

ApControl objects.<br />

ApControl knows how to ask<br />

ResFactory to instantiate drivers— it<br />

does not know (or care) how ResFactory<br />

is actually doing it.<br />

Learning the Abstract Factory Pattern:<br />

Implementing It<br />

Example 10-3 shows how to implement the Abstract Factory Implementation of<br />

objects for this design. the design

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

Saved successfully!

Ooh no, something went wrong!