Summary

Ordinary methods are usually templates in that you can't tell exactly what code will execute just by looking at a single method. The TEMPLATE METHOD pattern, however, does not merely note that ordinary methods are templates. Rather, the intent of TEMPLATE METHOD is to define an algorithm in a method, leaving some steps abstract, stubbed out, or defined in an interface so that other classes can fill them in.

TEMPLATE METHOD often functions as a contract between developers. One developer supplies the outline of an algorithm, and another developer supplies a certain step of the algorithm. This may be a step that lets the algorithm complete, or it may be a step that the algorithm developer includes to hook in your code at specific points ...

Get Design Patterns Java™ Workbook 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.