More Requirements for the Case Study

In Chapter 18, “The Template Method Pattern,” I ignored the issue of how to instantiate the database object required by my current context. I may not want to make the Client responsible for instantiating the database object. Instead, I might want to give that responsibility to the QueryTemplate class itself.

In Chapter 18, each derivation of the QueryTemplate was specialized for a particular database. Thus, I might want to make each derivation responsible for instantiating the database to which it corresponds. This would be true whether the QueryTemplate (and its derivations) was the only class using the database or not. Figure 19-1 shows this solution.

Figure 19-1. The Template Method (doQuery) using the ...

Get Design Patterns Explained: A New Perspective on Object-Oriented Design now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.