Iterator pattern

E679876

The Iterator pattern is a behavioral design pattern that provides a standard way to sequentially access elements of a collection without exposing its underlying representation.

Try in SPARQL Jump to: Statements Referenced by

Statements (49)

Predicate Object
instanceOf behavioral design pattern
software design pattern
alternativeName Cursor pattern
appliesWhen you need to access contents of an aggregate object without exposing its internal representation
you need to provide a uniform interface for traversing different aggregate structures
you need to support multiple traversal algorithms over an aggregate
belongsTo Gang of Four design patterns catalog
benefit enables consistent iteration APIs across different collections
improves encapsulation of collection classes
supports clean separation of concerns between data storage and traversal
category behavioral pattern
consequence allows different iterators to provide different traversal strategies
increases number of classes in a design
simplifies aggregate interface by moving traversal responsibility to iterator
supports multiple active iterators over the same aggregate
definedIn Design Patterns: Elements of Reusable Object-Oriented Software NERFINISHED
definesRole Aggregate interface
ConcreteAggregate class
ConcreteIterator class NERFINISHED
Iterator interface
describedBy Gang of Four NERFINISHED
encapsulates iteration state
traversal of a collection
firstPublished 1994
hasIntent provide a way to access elements of an aggregate object sequentially without exposing its underlying representation
hides internal representation of a collection
mapsTo C# System.Collections.IEnumerator interface NERFINISHED
C++ STL iterator concepts
Java java.util.Iterator interface NERFINISHED
participants Aggregate
ConcreteAggregate
ConcreteIterator NERFINISHED
Iterator
primaryGoal provide a uniform interface for iterating over different aggregate structures
separate traversal logic from collection structure
relatedTo Composite pattern NERFINISHED
Factory Method pattern NERFINISHED
Visitor pattern NERFINISHED
supports multiple simultaneous traversals
multiple traversal algorithms
polymorphic iteration over different collection types
sequential access to elements
typicalOperation currentItem()
first()
isDone()
next()
usedIn .NET collections
C++ Standard Template Library NERFINISHED
Java Collections Framework NERFINISHED

Referenced by (2)

Full triples — surface form annotated when it differs from this entity's canonical label.

Interpreter relatedTo Iterator pattern
Visitor collaboratesWith Iterator pattern