TryBestToCode Iterator (iterator)-object behavior pattern
1. intention
Provides a way to sequentially access elements in an aggregate object without exposing the object's internal representation.
2. alias
Cursor-Cursor.
3. motivation
An aggregate object should provide a way for others to access its elements without exposing its internal structure.
4. applicability
Access the contents of an aggregate object without exposing its internal representation.
Support multiple traversals of aggregated objects.
Provides a uniform interface for traversing different aggregation structures, i.e., supports polymorphic iterations.
5. structure
6. effect
The iterator pattern has three important functions:
Support for traversing an aggregation in different ways, complex aggregations can be traversed in multiple ways.
Iterators simplify the aggregation interface, and with iterator traversal interfaces, aggregation itself no longer requires similar traversal interfaces.
There can be multiple iterations on the same aggregate, and each iterator keeps its own traversal state, so you can do multiple iterations at the same time.