Iterator-mönstret tillhandahåller ett sätt att genomlöpa en samling sekventiellt utan att exponera dess interna struktur. Det är så fundamental att det är inbyggt i de flesta moderna språk (for-of-loopar, iteratorer, generatorer).
Vad Iterator-mönstret gör
ITERATOR → access elements of a collection SEQUENTIALLY without exposing its internals:
→ provides a standard way to traverse (next element, has more?)
→ the collection's internal structure (array, tree, linked list) is HIDDEN
→ decouples traversal logic from the collection
→ "iterate without caring how the collection is structured"
