Applied Design Patterns with Java
Behavioral :: Iterator (257) {C ch 19}
Applicability
Use the Iterator pattern:
- to access an aggregate object's contents without exposing
its internal representation.
- to support multiple traversals of aggregate objects.
- to provide a uniform interface for traversing different
aggregate structures (that is, to support polymorphic iteration).
Structure
Participants
- Iterator defines
an interface for accessing and traversing elements.
- ConcreteIterator implements the Iterator interface, and keeps track of the current position in the traversal
of the aggregate.
- Aggregate defines
an interface for creating an Iterator object.
- ConcreteAggregate implements
the Iterator
creation interface to return an instance of the proper ConcreteIterator.
Catalog Behavioral Prev Next