The Iterator pattern provides a consistent way to sequentially access items in a collection that is independent of and separate from the underlying collection.
The following lists the benefits of using the Iterator pattern:
- Supports variations in the traversal of a collection
- Simplifies the interface of the collection
You should use the Iterator pattern to:
- Access collection object’s contents without exposing its internal representation
- Support multiple traversals of objects in a collection
- Provide a uniform interface for traversing different structures in a collection