|
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.Objectdk.rode.thesis.meta.model.AbstractSequence<E>
dk.rode.thesis.meta.model.ArraySequence<String>
dk.rode.thesis.singleton.SimpsonsFamilySequence
dk.rode.thesis.singleton.MutatedSimpsonsFamilySequence
public final class MutatedSimpsonsFamilySequence
A mutated Simpsons family sequence is a sequence representing a random mutated sub-set of the primary family members in the one and only The Simpsons family.
This class can be sub-classed.
Implementation notes:
Even though the super class SimpsonsFamilySequence
is a singleton
class, this class is not. Creation and copying works like it does for
any other non-singleton sequence. This sequence is also cloneable,
but will still not create additional SimpsonsFamilySequence
instances.
It would in fact be possible to create SimpsonsFamilySequence
instances from the MutatedSimpsonsFamilySequence(int)
and
MutatedSimpsonsFamilySequence(MutatedSimpsonsFamilySequence)
constructors without the call to a super-constructor, i.e. using
new
. A caller
cannot determine how
the super-class constructor is invoked from a sub-class, only
from where. Hence, any singleton type that allows sub-classing
has to trust the sub-classes to some extent. However, it is not
possible even for sub-classes to invoke the super constructor from
other places than constructors. The evilCreation()
method is
test method that will try and create a SimpsonsFamilySequence
,
but will fail because it is not a constructor.
Even though this class references static fields in
SimpsonsFamilySequence
class, it will not cause the
SimpsonsFamilySequence
singleton instance to be
created.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
Sequence.State |
Field Summary |
---|
Fields inherited from class dk.rode.thesis.singleton.SimpsonsFamilySequence |
---|
members, SIZE |
Fields inherited from class dk.rode.thesis.meta.model.ArraySequence |
---|
elements, index |
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
state |
Constructor Summary | |
---|---|
MutatedSimpsonsFamilySequence()
No-arg constructor. |
|
MutatedSimpsonsFamilySequence(int members)
Constructor. |
|
MutatedSimpsonsFamilySequence(MutatedSimpsonsFamilySequence sequence)
Copy constructor. |
Method Summary | |
---|---|
MutatedSimpsonsFamilySequence |
clone()
Returns a clone of this sequence. |
MutatedSimpsonsFamilySequence |
copy()
Returns this instance. |
SimpsonsFamilySequence |
evilCreation()
Tries to create a SimpsonsFamilySequence instance based
on an off-limit constructor. |
private static String[] |
getMutatedMembers(int members)
Returns a mutated sub-set of the primary family members in The Simpsons family of size members . |
Methods inherited from class dk.rode.thesis.singleton.SimpsonsFamilySequence |
---|
equals, getFamily, hashCode |
Methods inherited from class dk.rode.thesis.meta.model.ArraySequence |
---|
bounded, consistent, current, next, reset, size, unique |
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence |
---|
getStringablePolicy, state, toString, toString |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface dk.rode.thesis.meta.model.Sequence |
---|
state |
Methods inherited from interface dk.rode.thesis.strategy.Stringable |
---|
getStringablePolicy, toString |
Constructor Detail |
---|
public MutatedSimpsonsFamilySequence()
Half the members of The Simpsons family will be included in this mutated sequence.
public MutatedSimpsonsFamilySequence(int members)
The number of members of the The Simpsons family included
in this sequence is specified by members
.
members
- The members; must be within
[1, SimpsonsFamilySequence.SIZE
].
IllegalArgumentException
- If members
is illegal.public MutatedSimpsonsFamilySequence(MutatedSimpsonsFamilySequence sequence)
sequence
- The sequence to copy; cannot be null.
NullPointerException
- If sequence
is null.Method Detail |
---|
public MutatedSimpsonsFamilySequence clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
- If the cloning fails.public MutatedSimpsonsFamilySequence copy()
SimpsonsFamilySequence
copy
in interface Sequence<String>
copy
in interface Copyable<Sequence<String>>
copy
in class SimpsonsFamilySequence
public SimpsonsFamilySequence evilCreation() throws SingletonError
SimpsonsFamilySequence
instance based
on an off-limit constructor. Doing so should cause
a SingletonError
to be thrown! If not, it
constitutes an internal error and the singleton invariant
is broken.
SingletonError
- Always thrown.private static final String[] getMutatedMembers(int members)
members
.
members
- The members; must be within
[1, SimpsonsFamilySequence.SIZE
].
IllegalArgumentException
- If members
is illegal.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |