|
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.memento.SequenceMemento<E> dk.rode.thesis.memento.GuardedSequenceMemento<E>
E
- The type of values delivered by applicable memorizable sequences.public class GuardedSequenceMemento<E>
A guarded sequence memento offer the same functionality
as SequenceMemento
, but enforce access rules to ensure
that only a (memorizable) sequence can set or get the memento
state.
Memento state is defined as data that can be set or acquired using
the the state methods setSequence(Sequence)
, getSequence()
,
and current()
, respectively.
Implementation notes:
All memento functionality has to be declared public if it must
be used outside this package. It cannot have "two interfaces" in
Java, a narrow (public) and a wide (public and private, using friends
to access private part), as described by Gamma et al. [Gamma95, p.285-287].
This implementation therefore divides the memento functionality into
two interfaces, namely GuardedSequenceMemento
(private part of
wide) and MemorizableSequence
(narrow, public). However, the
state methods setSequence(Sequence)
, getSequence()
,
and current()
still have to be public. To enforce an access check
at runtime, this class uses a CallerClass
to identify the caller
of the state methods, and only allows calls from valid contexts (memorizable
sequences). The GuardedSequenceMemento
class is thus a
Guarded Type.
Constructor Summary | |
---|---|
GuardedSequenceMemento()
No-arg constructor. |
|
GuardedSequenceMemento(Sequence<E> sequence)
Constructor. |
Method Summary | |
---|---|
E |
current()
Returns the value stored in the memorised sequence. |
Sequence<E> |
getSequence()
Return the sequence memorised by this memento. |
void |
setSequence(Sequence<E> sequence)
Memorises the state of the Sequence supplied as
sequence by copying it. |
Methods inherited from class dk.rode.thesis.memento.SequenceMemento |
---|
getStringablePolicy, toString, toString |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public GuardedSequenceMemento()
The sequence representing the state to memorise must
be set explicitly using the setSequence(Sequence)
method.
public GuardedSequenceMemento(Sequence<E> sequence)
sequence
- The sequence representing the state to
memorise; cannot be null. This memento does
not keep a reference to sequence
,
but copies it.
NullPointerException
- If sequence
is null.Method Detail |
---|
public final E current()
current
in class SequenceMemento<E>
IllegalStateException
- If no sequence has been set.
UnsupportedOperationException
- If the caller is not a sequence
of the type stored internally in this memento.public final Sequence<E> getSequence()
Mutating the returned sequence will not alter the internal state of this memento.
getSequence
in class SequenceMemento<E>
IllegalStateException
- If no sequence has been set.
UnsupportedOperationException
- If the caller is not a sequence
of the type stored internally in this memento.SequenceMemento.setSequence(Sequence)
public final void setSequence(Sequence<E> sequence)
Sequence
supplied as
sequence by copying it. The copy can then be retrieved
using the SequenceMemento.getSequence()
method.
setSequence
in class SequenceMemento<E>
sequence
- The sequence representing the state to
memorise; cannot be null. This memento does
not keep a reference to sequence
,
but copies it.
NullPointerException
- If sequence
is null.
IllegalStateException
- If a sequence has already been
set.
UnsupportedOperationException
- If sequence
does not have the
same class as the caller of this method.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |