|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
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() . |
Implementations and examples of the Prototype design pattern [Gamma95, p.117].
Intent:
Specify the kinds of objects to create using a prototypical instance, and create new objects by copying this prototype.
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.
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.
|
Gunni Rode / rode.dk | ||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |