|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.decorator.SequenceDecorator<E> dk.rode.thesis.visitor.AbstractVisitableSequence<E> dk.rode.thesis.visitor.ReflectiveVisitableSequence<E>
E
- The type of values delivered by this visitable sequence.@Participant(value="ConcreteElement") public class ReflectiveVisitableSequence<E>
A reflective visitable sequence decorates a
sequence
to become value
and type
visitable.
Implementation notes:
The Decorator pattern is used
to implement this visitable sequence.
The type visitable functionality is inherited from
AbstractVisitableSequence
, while the value visitable
functionality is implemented via reflection in this class
using type literals
.
In case the decorated sequence is generic itself, i.e. the type
of values to be delivered is specified using a type parameter,
the value type cannot be inferred. In such cases, the
SequenceVisitor.visitUnknown(Sequence, Object)
value
visitation method will be used. The visitUnknown
method
will also be used in case the type can be inferred, but is not
supported by the SequenceValueVisitor
interface, for
example a sequence delivering java.math.BigDecimal
values. Also note that only sequences delivering
java.lang.String
values can be inferred to the
SequenceValueVisitor.visitStringValued(Sequence, Object)
visitation
method, though it accepts any sequence delivering
java.lang.CharSequence
values. Hence,
decorating the HexDigitSequence
, for example, will cause the
visitUnknown
method to be used because no visitCharSequenceValued
visitation method is defined in the SequenceValueVisitor
interface. An alternative to allow more flexible visitation method
identification could be to use the Executor
annotation instead.
While reflection is used to invoke the value visitation method, type safety is still guaranteed as the invocation is made privately, using parameter types and values known to be correct.
DateValuedVisitableSequence
,
IntegerValuedVisitableSequence
,
StringValuedVisitableSequence
,
TypeLiteral
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Field Summary | |
---|---|
private Method |
visitationMethod
The value visitation method used by this sequence. |
private static Method |
visitUnknown
Default value visitation method, i.e. visit unknown type. |
Constructor Summary | |
---|---|
ReflectiveVisitableSequence(Sequence<E> sequence)
Constructor. |
Method Summary | ||
---|---|---|
|
accept(SequenceValueVisitor<P> visitor,
P argument)
Visits this visitable sequence using the value visitor supplied
as visitor . |
|
ReflectiveVisitableSequence<E> |
copy()
Returns a deep copy of this object. |
Methods inherited from class dk.rode.thesis.visitor.AbstractVisitableSequence |
---|
accept |
Methods inherited from class dk.rode.thesis.decorator.SequenceDecorator |
---|
bounded, consistent, current, equals, getSequence, getStringablePolicy, hashCode, next, reset, state, toString, toString, unique |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
bounded, consistent, current, next, reset, state, unique |
Methods inherited from interface dk.rode.thesis.strategy.Stringable |
---|
getStringablePolicy, toString |
Field Detail |
---|
private final Method visitationMethod
Never null.
private static final Method visitUnknown
Never null.
Constructor Detail |
---|
public ReflectiveVisitableSequence(Sequence<E> sequence)
In case sequence
is generic or delivers sequence values
that cannot be visited by a value
visitor, the SequenceVisitor.visitUnknown(Sequence, Object)
value visitation method will be used.
sequence
- The decorated sequence that will become visitable;
cannot be null.
NullPointerException
- If sequence
is null.Method Detail |
---|
public <P> void accept(SequenceValueVisitor<P> visitor, P argument)
ValueVisitableSequence
value
visitor supplied
as visitor
.
P
- The type of visitor-supplied argument. Use Void
for visitors that do not need an additional argument.visitor
- The visitor; never null.argument
- A context supplied argument, if any.SequenceValueScanner.scan(ValueVisitableSequence, SequenceValueVisitor, Object)
public ReflectiveVisitableSequence<E> copy()
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |