|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
---|---|
AbstractionFactory<E> | A sequence abstraction factory can create sequence
abstractions . |
GeneratorFactory<E,P> | A generator factory can create sequence value
generators used as implementations
for sequence abstractions . |
SequenceFactory<E,P> | A sequence factory provides a general
creation method to
create initialised sequences in a single step. |
Class Summary | |
---|---|
CollectionValueFactory<E extends Serializable> | A collection value factory creates specific SequenceValueCollection
objects based on the supplied type of collection to the creation method. |
Main | Abstract Factory tests. |
MemorizableAbstractionFactory<E> | A memorizable abstraction factory creates
memorizable sequence
abstractions. |
PrototypicalAbstractionFactory<E> | A prototypical abstraction factory creates
sequence abstractions based on
a prototype supplied at construction time. |
PrototypicalFactory<T extends StrictCopyable<T>> | A prototypical factory creates instances of a specific type of
copyable type based on a prototype supplied at
construction time. |
PrototypicalRegistry | A prototypical registry creates instances of
copyable objects based on
registered
prototypes. |
PrototypicalSequenceFactory<E> | A prototypical sequence factory creates sequences
based on a prototype supplied at construction time. |
RangeValueFactory | A range value factory creates value range
generators. |
StandardAbstractionFactory<E> | A standard abstraction factory creates
sequence abstractions. |
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. |
SynchronisedAbstractionFactory<E> | A synchronised abstraction factory creates
synchronised sequence
abstractions. |
Implementations and examples of the Abstract Factory design pattern [Gamma95, p.87].
Intent:
Provide an interface for creating families of related or dependent objects without specifying their concrete classes.
SequenceAbstraction
,
SequenceValueGenerator
, and
Sequence
types. Hence, the
ConcreteProduct participant is represented by any class
inheriting or implementing the aforementioned types, including
SequenceAbstraction
itself.
A factory type is defined to create each of the abstract product
types, respectively the AbstractionFactory
,
GeneratorFactory
, and
SequenceFactory
interfaces.
All theses factories represent the AbstractFactory participant.
Several different factory implementations have been made to
represent the ConcreteFactory participant, each capable of
creating one or more of described product types. The
StandardFactory
implements
all three factory types, but uses composition to let
AbstractionFactory
and GeneratorFactory
instances
perform the actual creation; sequences created by it are simply
initialised SequenceAbstraction
instances. Specific
abstraction factories include
StandardAbstractionFactory
and
MemorizableAbstractionFactory
, while
CollectionValueFactory
and
RangeValueFactory
are the only two
generator factories.
Several prototypical factories are also provided, that create products based
on prototypes. The PrototypicalFactory
is a stand-alone prototypical factory, while the PrototypicalRegistry
class is a registry that can create multiple product types.
Finally, the Client participant is represented by the
Main
class, which creates
and uses the created sequences.
Implementation notes:
The PrototypicalSequenceFactory
factory
illustrates how the Prototype pattern can
be used to create objects based on prototypes. The PrototypicalSequenceFactory
can create any type of sequence based on a prototype supplied at construction time.
The PrototypicalAbstractionFactory
provides
similar functionality, but for SequenceAbstraction
instances.
The use of prototypes is a possible alternative to using reflection to create different types
of products. However, the PrototypicalRegistry
illustrates that using a registry to store prototypes to create can cause problems with
type safety when generic types are created. The generic
Factory
class illustrates how reflection can be used
to make a completely generic factory type to create any type of instantiable product,
providing the product type has a usable constructor. Ideally, it should be used in
an Abstract Factory implementation via composition, but here we simply illustrate its
use directly in Main
and combine products as need be.
|
Gunni Rode / rode.dk | ||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |