Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.abstractfactory
Class PrototypicalFactory<T extends StrictCopyable<T>>

java.lang.Object
  extended by dk.rode.thesis.abstractfactory.PrototypicalFactory<T>
Type Parameters:
T - The type of values created by this factory.
Direct Known Subclasses:
PrototypicalSequenceFactory

@ParticipantUsage(value="ConcreteProduct",
                  type=StrictCopyable.class)
@Participant(value="ConcreteFactory")
public class PrototypicalFactory<T extends StrictCopyable<T>>
extends Object

A prototypical factory creates instances of a specific type of copyable type based on a prototype supplied at construction time.

This factory is thread-safe.

Implementation notes:
Using the Prototype pattern as a means to create different types of sequences is an, perhaps safer, alternative to creating sequences using reflection. The Factory type illustrates how reflection can be used in the creation process.

Author:
Gunni Rode / rode.dk
See Also:
PrototypicalRegistry

Field Summary
private  T prototype
          The prototypical object to use.
 
Constructor Summary
PrototypicalFactory(T prototype)
          Constructor.
 
Method Summary
 T create()
          Creates a new instance based on the prototypical object supplied at construction time.
 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

prototype

private final T extends StrictCopyable<T> prototype
The prototypical object to use.

Never null.

Constructor Detail

PrototypicalFactory

public PrototypicalFactory(T prototype)
Constructor.

prototype is copied and this factory keeps no reference to it.

Parameters:
prototype - The prototypical object to use; cannot be null.
Throws:
NullPointerException - If prototype is null.
Method Detail

create

public T create()
Creates a new instance based on the prototypical object supplied at construction time.

Returns:
The new instance; never null.

toString

public String toString()
Returns the string representation of this factory.

Overrides:
toString in class Object
Returns:
The string representation; never null.

Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.