Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6
|PREV PACKAGE NEXT PACKAGE||FRAMES NO FRAMES|
|SequenceTypeScanner||A sequence type scanner performs the actual traversal
|SequenceTypeVisitor<P>||A sequence type visitor visits a
|SequenceValueScanner||A sequence value scanner performs the actual traversal
|SequenceValueVisitor<P>||A sequence value visitor visits a
|SequenceVisitor<P>||A sequence visitor is the super type for all visitors that
can visit a
|TypeVisitableSequence<E>||A type visitable sequence allows visitation
|ValueVisitableSequence<E>||A value visitable sequence allows visitation
|AbstractVisitableSequence<E>||Any sequence decorated by an abstract visitable sequence
|CountingVisitor||A counting visitor counts the different types of
|DateValuedVisitableSequence||A date valued visitable sequence allows any
|IntegerValuedVisitableSequence||An integer valued visitable sequence allows any
|LoggingVisitor||A logging visitor logs each visited
|ReflectiveVisitableSequence<E>||A reflective visitable sequence decorates a
|SimpleScanner||A simple scanner can traverse both
|StringValuedVisitableSequence<E extends CharSequence>||A string valued visitable sequence allows any
|TypeVisitor||A type visitor collects visited
|VisitableCompositeSequence||An visitable composite sequence is
|VisitableLongSequence||A visitable long sequence is a
|VisitableRandomSequence||A visitable random sequence is a
|VisitableReversiblePrimeSequence||A visitable reversible prime sequence is a
Implementations and examples of the Visitor design pattern [Gamma95, p.331].
Represent an operation to be performed on the elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates.
SequenceValueVisitorclasses. The first is a type visitor to visit a given
Sequencebased on its type, e.g.
ReversibleSequence, while the latter is a value visitor that visits based on the type of sequence values, e.g.
CharSequence, etc. The use of two different visitors help illustrate visitor usage more clearly than just using a single type.
The Element participant is represented by the
interfaces, respectively for visitation by
SequenceValueVisitor implementations. A given
Sequence may naturally implement both interfaces. The
ConcreteElement participant is represented by any sequence
that implement either or both of these interfaces.
The ConcreteVisitor participant is represented by any
implementation. In this package, three visitors are implemented,
(value visitor), and
and value visitor).
A tree-like element (sequence) structure is achieved by using the
combined with non-composite (visitable) sequences. To traverse
Sequence structure for a given type or value
implementations should be used, respectively. They represent the
ObjectStructure participant. A concrete implementation has been
made than can traverse a sequence structure for both type and
value visitors in form of
This package defines three concrete visitable sequences (excluding
the composite visitable sequence):
The first is only visitable by value visitors, while last two
can be visited by both type and value visitors.
A visitable sequence rarely adds new state to the sequence it
inherits. In fact, the primary reason for inheritance is to
ValueVisitableSequence interfaces because of Java's
fixed class structure. To avoid overly use of inheritance, several
wrappers (decorators) have been developed in this package
that will wrap a given sequence and make it visitable. For example,
class allows any
Sequence<? extends CharSequence> type
to become both type and value visitable. Such wrappers
Finally, a reflective wrapper in form of the
ReflectiveVisitableSequence class has been
created that allows any sequence to become both value and type
visitable based on reflective
UML Class Diagram:
Though two different types of visitors are used, they operate on the same class hierarchy, i.e.
Sequence, but with different
focus, i.e. sequence type vs. sequence values.
SequenceTypeVisitor implementations are not completely
accurate when decorated, adapted, and/or proxied sequences are
used, because the
instanceof test will fail in such cases.
However, this is a general problem related to the use of decorators,
adapters, and proxies, not specifically to visitors.
class can make any sequence visitable, it may not be able to infer
the correct sequence value type in case the sequence is generic. The
sequence in question may also deliver a value not supported by the
SequenceValueVisitor interface. In such cases, the
default visitation method is used.
In the implementation here, visiting a composite sequence is just
like visiting a non-composite sequence, because the
implementations, respectively, will handle the sequence traversal
|Gunni Rode / rode.dk|
|PREV PACKAGE NEXT PACKAGE||FRAMES NO FRAMES|