Iterator Pattern

The Iterator pattern provides a consistent way to sequentially access items in a collection that is independent of and separate from the underlying collection. 

UML representation


The following lists the benefits of using the Iterator pattern:
  • Supports variations in the traversal of a collection
  • Simplifies the interface of the collection

When to Use

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
Subpages (1): Iterator Pattern Example