System Design
15. Software Design PatternsAnimated walkthrough
Iterator Pattern
Walk through a collection without exposing it.
The idea
An iterator offers next and has-next across any structure.
Watch it work
The steps light up one at a time. Use the controls to pause or step through.
- 1Ask the collection for an iterator
- 2Call next
- 3Process each item
- 4Stop at the end
1/4
Step by step
- 1Ask the collection for an iterator
- 2Call next
- 3Process each item
- 4Stop at the end
Where it is used
Looping over structures.
Watch out for
Modifying the collection while iterating.