An iterator is an object-oriented programming pattern that allows traversal through a collection, agnostic of the actual implementation or object addresses in physical memory. It is one of the Gang of Four's behavioral design patterns.
An iterator is an object-oriented programming pattern which for the most part functions similarly to a pointer to an object inside a collection with the added ability to traverse through the collection in a defined manner, agnostic of the actual implementation or even object addresses in physical memory.
The following types of iterators are the most common:
- Forward
- Reverse
- Bidirectional
- Random Access
Iterators may be read-only, write-only or read-write.
Forward iterators typically have a next
Reverse iterators typically have a previous
and
sometimes iterators have a remove
method.
This is one of the Gang of Four's behavioral design-patterns, first published in Gamma et al.'s book "Design Patterns: Elements of Reusable Object-Oriented Software".
The Gang of Four pattern is discussed separately on Wikipedia.