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.

168 Part III • <strong>Design</strong> <strong>Patterns</strong><br />

Defining the objects this way would allow for ApControl to use a<br />

DisplayDriver and a PrintDriver without using switches.<br />

ApControl is much simpler to understand because it does not have<br />

to worry about the type of drivers it has. In other words, ApControl<br />

would use a DisplayDriver object or a PrintDriver object<br />

without having to worry about the driver's resolution.<br />

See Figure 10-3 and the code in Example 10-2.<br />

Figure 1O-3 ApControl using drivers in the ideal situation.<br />

Example 1O-2 Java Code Fragments: Using<br />

Polymorphism to Solve the Problem

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

Saved successfully!

Ooh no, something went wrong!