|
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.abstractfactory.StandardFactory<E,P>
E
- The type of values delivered by the created abstractions and
generators.P
- The type of argument required in the creation process of
generators. Use Void
if no arguments are required.@Participant(value="ConcreteFactory") public class StandardFactory<E,P>
A standard factory can create sequence
abstractions
as well as the sequence
value generators
used as the
implementations for the abstractions, and further more provides
a convenient creation method
to
create sequences in a single step.
Implementation notes:
This factory works by composition: attached AbstractionFactory
and
GeneratorFactory
instances perform the actual creation, and
they can be changed at runtime, making this factory very flexible.
PrototypicalSequenceFactory
,
SequenceFactory
,
AbstractionFactory
,
GeneratorFactory
Field Summary | |
---|---|
private AbstractionFactory<E> |
abstractionFactory
The currently used abstraction factory. |
private GeneratorFactory<E,P> |
generatorFactory
The currently used generator factory. |
Constructor Summary | |
---|---|
StandardFactory()
Constructor. |
|
StandardFactory(AbstractionFactory<E> abstractionFactory,
GeneratorFactory<E,P> generatorFactory)
Constructor. |
Method Summary | |
---|---|
SequenceAbstraction<E> |
createAbstraction()
Creates a new sequence abstraction instance. |
SequenceValueGenerator<E> |
createGenerator()
Creates a new sequence value generator using the default argument. |
SequenceValueGenerator<E> |
createGenerator(P argument)
Creates a new sequence value generator, where argument is an
argument used in the creation process of the generator. |
Sequence<E> |
createSequence(P argument)
Creates a new initialised sequence instance. |
AbstractionFactory<E> |
getAbstractionFactory()
Returns the abstraction factory
currently used by this factory. |
P |
getDefaultArgument()
Returns the default argument to use for generator creation in case no argument is supplied to the GeneratorFactory.createGenerator(Object)
method. |
GeneratorFactory<E,P> |
getGeneratorFactory()
Returns the generator factory
currently used by this factory. |
void |
setAbstractionFactory(AbstractionFactory<E> abstractionFactory)
Sets the abstraction factory
to use by this factory to abstractionFactory . |
void |
setGeneratorFactory(GeneratorFactory<E,P> generatorFactory)
Sets the generator factory
to use by this factory to generatorFactory . |
String |
toString()
Returns the string representation of this factory. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private AbstractionFactory<E> abstractionFactory
The factory may change at runtime.
Will be null until explicitly set.
private GeneratorFactory<E,P> generatorFactory
The factory may change at runtime.
Will be null until explicitly set.
Constructor Detail |
---|
public StandardFactory()
Abstraction
and generator
factories must be explicit set before this factory can be used to create
abstractions and generators, respectively.
setAbstractionFactory(AbstractionFactory)
,
setGeneratorFactory(GeneratorFactory)
public StandardFactory(AbstractionFactory<E> abstractionFactory, GeneratorFactory<E,P> generatorFactory)
The abstraction
and generator
factories supplied as abstractionFactory
and
generatorFactory
will be set as the factories used,
respectively. They can be changed at runtime if so desired.
abstractionFactory
- The abstraction factory to use; cannot be null.generatorFactory
- The generator factory to use; cannot be null.
NullPointerException
- If either argument is null.setAbstractionFactory(AbstractionFactory)
,
setGeneratorFactory(GeneratorFactory)
Method Detail |
---|
public SequenceAbstraction<E> createAbstraction()
AbstractionFactory
abstraction
instance.
Depending on the actual factory implementation, the returned abstraction
may be initialised
. If so, no
implementation need be set.
createAbstraction
in interface AbstractionFactory<E>
public SequenceValueGenerator<E> createGenerator()
GeneratorFactory
default
argument.
createGenerator
in interface GeneratorFactory<E,P>
GeneratorFactory.createGenerator(Object)
,
GeneratorFactory.getDefaultArgument()
public SequenceValueGenerator<E> createGenerator(P argument)
GeneratorFactory
argument
is an
argument used in the creation process of the generator.
createGenerator
in interface GeneratorFactory<E,P>
argument
- A context supplied argument to use in the construction of the
generator, if any. If null, the default
argument is used (which may also be null, depending
on the actual implementation).
GeneratorFactory.createGenerator()
public Sequence<E> createSequence(P argument)
sequence
instance.
First, a SequenceAbstraction
is created by the
abstraction factory
currently
used. If the abstraction is initialised
, it will be returned. If not, a generator
will be created using the argument supplied as argument
,
if any, by the generator factory
currently
used. If no argument is supplied, the default
argument is used. Then the generator is attached as the implementation for the
created abstraction, which is finally returned.
createSequence
in interface SequenceFactory<E,P>
argument
- A context supplied argument to use in creation process. If
the created abstraction is initialised, the argument is
unused. Can be null, in which case the default argument
is used.
public AbstractionFactory<E> getAbstractionFactory()
abstraction
factory
currently used by this factory.
public P getDefaultArgument()
GeneratorFactory
GeneratorFactory.createGenerator(Object)
method.
getDefaultArgument
in interface GeneratorFactory<E,P>
public GeneratorFactory<E,P> getGeneratorFactory()
generator
factory
currently used by this factory.
public void setAbstractionFactory(AbstractionFactory<E> abstractionFactory)
abstraction
factory
to use by this factory to abstractionFactory
. Any previously set abstraction factory will be discarded, if any.
abstractionFactory
- The factory; cannot be null.
NullPointerException
- If abstractionFactory
is null.public void setGeneratorFactory(GeneratorFactory<E,P> generatorFactory)
generator
factory
to use by this factory to generatorFactory
. Any previously set generator factory will be discarded, if any.
generatorFactory
- The factory; cannot be null.
NullPointerException
- If generatorFactory
is null.public String toString()
toString
in class Object
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |