Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides
"Define the skeleton of an algorithm in an operation, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithms structure." (Gamma, E., R. Helm, R. Johnson, and J. Vlissides. Design Patterns: Elements of Reusable Object-Oriented Software. Reading, MA: Addison-Wesley, 1995)
Consider an application framework that provides Application and Document classes. The Application class is responsible for opening existing documents stored in an external format, such as a file. A Document object represents the information in a document once its read from the file. Applications built with the framework can subclass Application and Document to suit specific needs. For example, a drawing application defines DrawApplication and DrawDocument subclasses; a spreadsheet application defines SpreadsheetApplication and SpreadsheetDocument subclasses. The abstract Application class (AbstractClass in the thumbnail) defines the algorithm for opening and reading a document in its OpenDocument operation. OpenDocument defines each step for opening a document. It checks if the document can be opened, creates the application-specific Document object, adds it to its set of documents, and reads the Document from a file. OpenDocument is a template method. A template method defines an algorithm in terms of abstract operations that subclasses override to provide concrete behavior. Application subclasses define the steps of the algorithm that check if the document can be opened (CanOpenDocument) and that create the Document (DoCreateDocument). Document classes define the step that reads the document (DoRead). The template method also defines an operation that lets Application subclasses know when the document is about to be opened (AboutToOpenDocument). By defining some of the steps of an algorithm using abstract operations, the template method fixes their ordering, but it lets Application and Document subclasses vary those steps to suit their needs. Known Uses Template methods are found in almost every abstract class. For a good overview and discussion of Template Methods patterns see: "Wirfs-Brock, R., B. Wilkerson, and L. Wiener. Designing Object-Oriented Software. Prentice Hall, Englewood Cliffs, NJ, 1990" or "Wirfs-Brock R. and R.E. Johnson. A survey of current research in object-oriented design. Communications of the ACM, 33(9):104-124, 1990."
Template methods are found in almost every abstract class. For a good overview and discussion of Template Methods patterns see: "Wirfs-Brock, R., B. Wilkerson, and L. Wiener. Designing Object-Oriented Software. Prentice Hall, Englewood Cliffs, NJ, 1990" or "Wirfs-Brock R. and R.E. Johnson. A survey of current research in object-oriented design. Communications of the ACM, 33(9):104-124, 1990."
Factory Methods and Strategy patterns

Factory Method pattern, Strategy pattern, Template Method pattern, behavioral patterns, Gamma patterns, behavior distribution (class), algorithm (step-by-step), redefine algorithms
any system requiring dynamic behavioral assignments to objectsany system with high degree of behavioral variation
need flexibility in creating various complex objectsneed many algorithms with variation
allows you to vary the behavior of a class independent of its contextchangeability and extensibility of componentsreusability
Simple implementation of the pattern - ConcreteClass class. ConcreteClass.javaSimple implementation of the pattern - AbstractClass class. AbstractClass.javaTest driver testtemplate.cppSimple implementation of the pattern. template.h