Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

@Pattern(name="Template Method", scope=Class, purpose=Behavioural, participants={"AbstractClass","ConcreteClass"})

Package dk.rode.thesis.templatemethod

Implementations and examples of the Template Method design pattern [Gamma95, p.325].

See:
          Description

Class Summary
FileSequence A file sequence delivers byte arrays as sequence values, where each array corresponds to the contents of the current file or directory in a given directory.
Main Template Method tests.
NegativeSequence A negative sequence represents a perhaps bounded integer value that is decreased with each call to next(), starting at minus one.
SequenceTemplate<K,E> A sequence template forms a template for sequences requiring several steps to construct, deliver, and dispose sequence values.
ZipSequence A zip sequence delivers input streams as sequence values, where each stream correspond to the current zip file entry.
 

Exception Summary
SequenceValueException A sequence value exception is thrown by a sequence template in case of value related errors, such as initialisation error, a next value cannot be delivered, or if the sequence is closed.
 

Package dk.rode.thesis.templatemethod Description

Implementations and examples of the Template Method design pattern [Gamma95, p.325].

Intent:

Here, the AbstractClass participant is represented by the SequenceTemplate class. It allows the creation of sequence values to be considered as a multi-step process like open-value, get-value, and close-value.

The ConcreteClass participant is represented by the actual sub-classes of the abstract class participant, namely NegativeSequence, FileSequence, and ZipSequence.

UML Class Diagram:

Implementation notes:
Java does not support functional multiple inheritance. Hence, any concrete class can at most inherit functionality from one abstract class. An alternative is to define the required template methods in a single interface. The abstract and concrete classes can implement this interface, but the actual implementation can be a component which is used through composition in the concrete class. This approach can also be combined with inheritance.

Author:
Gunni Rode / rode.dk

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.