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

@Pattern(name="Prototype", scope=Object, purpose=Creational, participants={"Prototype","ConcretePrototype","Client"})

Package dk.rode.thesis.prototype

Implementations and examples of the Prototype design pattern [Gamma95, p.117].

See:
          Description

Interface Summary
Copyable<T> A copyable object can return a deep copy of it self any type implementing this interface can act as a prototype.
StrictCopyable<T extends StrictCopyable<T>> A strict copyable object can return a deep copy of it self any type implementing this interface can act as a prototype.
 

Class Summary
CountdownSequence A non-copyable count-down sequence is a singleton sequence used for count-downs: Five, Four, Three, Two, One, FIRE!
Main Prototype tests.
PrototypeFactory A prototype factory creates various dynamic proxies that allows any object to become copyable, if not already, if it supplies a copy constructor.
SymbolSequence A cloneable symbol sequence can be cloned by using the SymbolSequence.copy() method, or by using Java's built-in clone mechanism by calling SymbolSequence.clone().
 

Package dk.rode.thesis.prototype Description

Implementations and examples of the Prototype design pattern [Gamma95, p.117].

Intent:

Here, the Prototype participant is represented by the Copyable interface and any Copyable implementation is thus a representative of the ConcretePrototype participant.

The Sequence interface extends Copyable. This effectively makes every Sequence implementation a representative of the ConcretePrototype participant as well. This package explicitly defines two concrete prototypical sequences, namely the CountdownSequence and SymbolSequence classes.

Furthermore, the Proxy pattern is used to generate dynamic proxies via the PrototypeFactory class that makes any type (represented by an interface) copyable if the type implements Copyable, naturally, and/or if it supplies a copy constructor. Hence, any such object also becomes a representation of the ConcretePrototype pattern.

The Client participant is represented by the test application, i.e. the Main class, which asks the prototypes to copy themselves. The Main class also illustrates how to make instances of the non-copyable SequenceIterator class dynamically copyable by using the PrototypeFactory class.

UML Class Diagram:

Implementation notes:
The SymbolSequence type also supports Java's built in clone functionality. Any type implementing the java.lang.Cloneable interface is also a representative of the Prototype participant.

Author:
Gunni Rode / rode.dk

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.