Iterator Pattern
Overview
Provide a way to access the elements on an aggregate object sequentially without exposing
its underlying representation.
Participants
- defines an interface for accessing and traversing elements.
- implements the Iterator interface.
- keeps track of the current position in the traversal of the aggregate.
- is optional as this class it automatically created when the pattern is applied.
- defines an interface for creating an Iterator object.
- implements the Iterator creation interface to return an instance of the proper ConcreteIterator.
Parameters
- name of the method for getting the next object in the iteration.
- name of the method to see if more objects remain in the iteration during traversal.
-
when selected, will create special JavaDoc links in the code between pattern participants, describing
their relationships.
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).