Iterator design pattern

E679869

The Iterator design pattern is a behavioral pattern that provides a standard way to sequentially access elements of a collection or aggregate object 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 NERFINISHED
applicableWhen you need multiple ways to traverse a collection
you want to keep collection classes focused on storage rather than traversal
you want to provide a uniform interface for traversing different aggregate structures
belongsTo Gang of Four design patterns NERFINISHED
canBeExtendedWith filtered iteration
lazy iteration
reverse iteration
canSupport internal iteration
category behavioral pattern
consequence increases number of objects in the system
simplifies aggregate interface
supports multiple simultaneous traversals of the same aggregate
decouples collection structure from traversal algorithm
definesOperation currentItem()
first()
hasNext()
next()
definesRole Aggregate defines interface for creating an iterator object
ConcreteAggregate implements iterator creation for a concrete collection
ConcreteIterator implements traversal for a specific aggregate NERFINISHED
Iterator provides interface for accessing and traversing elements
describedIn Design Patterns: Elements of Reusable Object-Oriented Software NERFINISHED
encapsulates traversal logic of a collection
ensures clients do not need to know collection’s internal data structure
goal allow clients to traverse collections without depending on their concrete classes
hides internal representation of aggregate objects
participants Aggregate
ConcreteAggregate NERFINISHED
ConcreteIterator NERFINISHED
Iterator NERFINISHED
primaryIntent provide a way to access elements of an aggregate object sequentially without exposing its underlying representation
promotes open/closed principle for traversal strategies
single responsibility principle for collections
relatedTo Composite design pattern NERFINISHED
Factory Method design pattern NERFINISHED
supports different traversal strategies for the same aggregate
external iteration
polymorphic iteration over different collection types
sequential access to elements
uniform traversal over arrays, lists, trees, and other aggregates
typicalMethodName begin()
end()
iterator()
usedIn .NET collections
C++ Standard Template Library NERFINISHED
Java Collections Framework NERFINISHED

Referenced by (1)

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

Composite relatedTo Iterator design pattern