|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
---|---|
CompositeSequence<E> | A composite sequence is a sequence that represents an number of other contained sequences, possibly composite as well. |
Class Summary | |
---|---|
AbstractCompositeSequence<E> | An abstract composite sequence implements the basic traits
of the CompositeSequence interface. |
CharSequenceCompositeSequence | A char-sequence composite sequence is a composite sequence
parameterised with the CharSequence type. |
Main | Composite tests. |
Enum Summary | |
---|---|
CompositePolicy | Additional policies for formatting SequenceDecorator
objects into char sequences (not part of the core Composite
implementation). |
CompositeStrategy | Strategies for traversing composite sequence
graphs. |
Implementations and examples of the Composite design pattern [Gamma95, p.163].
Intent:
Compose objects into tree structures to represent part—whole hierarchies. Composite lets clients treat individual objects and compositions of objects uniformly.
CompositeSequence
class.
It allows for Sequence
objects to be composed into tree like structures and sequences
thus represent both the Component (by inheriting the
Sequence
interface) and Leaf (contained in composites)
participants.
The Client participant is the test application, i.e. the
Main
class.
Implementation notes:
This Composite implementation opts for type-safety over transparency
as discussed by Gamma et al. [Gamma95, p.167-168]. Child management
is defined in the Composite (CompositeSequence
) participant
because it can never make sense for Leaf components (Sequence
).
Unlike C++, the instanceof
operator in Java provides a safe way to
cast to a given type.
No explicit parent references are maintained for Sequence
objects
contained in a CompositeSequence
. Sharing cannot generally be
recommended because sequences carry state that is very likely to be manipulated
through the Sequence
interface, which CompositeSequence
inherits.
Explicit child ordering is possible by using a CompositeStrategy
,
such as CompositeStrategy.DEPTH_FIRST
.
A limitation in the SequenceComposite
interface is that
each contained sequence must be declared to use or extend the same
type parameter at construction time. However, it may be possible to use
the Adapter pattern to
circumvent this.
This package defines a basic abstract implementation of the
CompositeSequence
interface, namely the
AbstractCompositeSequence
class. It stores child sequences in a random-access list for fast
traversal. Child-related operations are not thread-safe. The
CharSequenceCompositeSequence
class
is an actual implementation of the CompositeSequence
interface.
|
Gunni Rode / rode.dk | ||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |