= Solution
The <iterator pattern> exposes sequential traversal through a small interface while hiding the representation of the underlying data. A client asks whether another entry is available and requests the next entry; it need not know whether the producer uses an <array>, <linked list>, tree or generated <sequence>.
The key design benefit is \b[<encapsulation> of traversal state and representation]. The same consuming <algorithm> can work through the interface for different producers, and each traversal can keep its own cursor state when a fresh <iterator> is supplied. This independence requires separate consumption states; two references to one <iterator> share a cursor.
Back to article page