Pattern 6Replacing Template Method

Intent

To specify the outline of an algorithm, letting callers plug in some of the specifics

Overview

The Template Method pattern consists of an abstract class that defines some operation, or set of operations, in terms of abstract suboperations. Users of Template Method implement the abstract template class to provide implementation of the substeps. A template class looks like this code snippet:

 
public​ ​abstract​ ​class​ TemplateExample{
 
 
public​ ​void​ anOperation(){
 
subOperationOne();
 
subOperationTwo();
 
}
 
 
protected​ ​abstract​ ​void​ subOperationOne();
 
 
protected​ ​abstract​ ​void​ subOperationTwo();
 
}

To use it, extend the TemplateExample and implement the abstract suboperations. ...

Get Functional Programming Patterns in Scala and Clojure 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.