Il-pattern Iterator jipprovdi mod biex tavvala koleksjoni sekwenzjalment mingħajr ma tesponi l-istruttura interna tagħha. Huwa tant fundamentali li hu integrat fil-biċċa l-kbira tal-lingwi moderni (for-of loops, iterators, generators).
X'jagħmel il-pattern Iterator
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"
