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.

All labels observed (2)

Label Occurrences
Iterator pattern canonical 4
Iterator 1

How this entity was disambiguated

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
definesRole Aggregate interface
ConcreteAggregate class
ConcreteIterator class
Iterator interface
describedBy Gang of Four
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
linked to: System.Collections

C++ STL iterator concepts
Java java.util.Iterator interface
linked to: java.util.Iterator
participants Aggregate
ConcreteAggregate
ConcreteIterator
Iterator
primaryGoal provide a uniform interface for iterating over different aggregate structures
separate traversal logic from collection structure
relatedTo Composite pattern
Factory Method pattern
linked to: Factory Method

Visitor pattern
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
Java Collections Framework
linked to: Java Class Library

How these facts were elicited

Referenced by (5)

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

Interpreter relatedTo Iterator pattern
Visitor collaboratesWith Iterator pattern
Iterator design pattern participants Iterator
linked to: Iterator pattern
Composite pattern relatedTo Iterator pattern
Gang of Four design pattern hasExample Iterator pattern