|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
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 . |
Implementations and examples of the Template Method design pattern [Gamma95, p.325].
Intent:
Define the skeleton of an algorithm in an operation, deferring some steps to sub—classes. Template Method lets sub—classes redefine certain steps of an algorithm without changing the algorithm's structure.
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
.
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.
|
Gunni Rode / rode.dk | ||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |