Field Notes: Using the Template Method Pattern

Sometimes a class will use several different Strategy patterns. When I first looked at the class diagram for the Template Method, I thought, “Oh, the Template Method is simply a collection of Strategies that work together.” This is dangerous (and usually incorrect) thinking. While it is not uncommon for several Strategies to appear to be connected to each other, designing for this can lead to inflexibility.

The Template Method is applicable when there are different, but conceptually similar processes. The variations for each process are coupled together because they are associated with a particular process. In the example I presented, when I need a format a CONNECT command for an Oracle database, ...

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.