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.

28O Part V • Handling Variations with <strong>Design</strong> <strong>Patterns</strong><br />

... but the details<br />

differ<br />

Standardizing on the<br />

steps<br />

The details are<br />

varying<br />

4. Send the database the SELECT command.<br />

5. Return the selected dataset.<br />

The specific implementations of the databases differ, however,<br />

requiring slightly different formatting procedures.<br />

The Template Method Pattern<br />

The Template Method is a pattern intended to help one abstract out a<br />

common process from different procedures. According to the<br />

Gang of Four, the intent of the Template method is to<br />

Define the skeleton of an algorithm in an operation,<br />

deferring some steps to subclasses. Redefine the steps in<br />

an algorithm without changing the algorithm's structure. 1<br />

In other words, although there are different methods for connecting<br />

and querying Oracle databases and SQL Server databases, they share<br />

the same conceptual process. The Template Method gives us a way to<br />

capture this common ground in an abstract class while<br />

encapsulating the differences in derived classes. The Template<br />

Method pattern is about controlling a sequence common to different<br />

processes.<br />

Applying the Template Method<br />

to the Case Study<br />

In this case study, the variations in database access occur in the particular<br />

implementations of the steps involved. Figure 18-1 illustrates<br />

this.<br />

1. Gamma, E., Helm, R., Johnson, R., Vlissides, J., <strong>Design</strong> <strong>Patterns</strong>: Elements of<br />

Reusable Object-Oriented Software, Reading, Mass.: Addison-Wesley, 1995, p. 325.

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

Saved successfully!

Ooh no, something went wrong!