Keywords: current

Next: 1.5.1.5 Body Up: 1.5.1 The Design Recipe Previous: 1.5.1.3 Examples

### 1.5.1.4 Template

In Java, much of the template selection process is mandated by the object-oriented programming model. When a data type T consisting of several different forms of data is represented by a composite class hierarchy, each method m defined on T must be defined in the class `T` corresponding to `T`. With a few rare exceptions, the method definition for m in `T` must be `abstract`, forcing each concrete subclass of `T` to provide a definition for m. In each variant class `V`, the relevant data for each definition of m is simply the set of object fields in `V`.

The only features in the template for a Java method definition that are not dictated by the object-oriented programming model are the recursive method calls corresponding to circular references in the data definition. For any method m in a class `C` containing a object field f of type T where T is a supertype of `C` (e.g. `C` is a concrete class in a composite class hierarchy with `T` at the top), the body of m will usually invoke m recursively on each such field f. These recursive calls appear in the template. For a concrete example, see Section 1.5.2.

Next: 1.5.1.5 Body Up: 1.5.1 The Design Recipe Previous: 1.5.1.3 Examples