Intent
Provide a way to access the elements of an aggregate sequentially without
exposing the underlying representation.
Applicability
- uniform traversal interface over different structures
- provide different traversals
Structure
[to do: diagram with Aggregate and Iterator]
Consequences
- algorithms can be implemented independent of representation
- encapsulation is preserved
Implementation
- who controls traversal
- internal versus external iterators
- robust iterators: what happens when the aggregate is modified while iterator
is active
- iterator is adjusted
- avoid it by iterating over a copy (expensive)
Uses in JHotDraw
- JHotDraw uses Iterators of the Java Collections API in many places