Soláthraíonn an patrún Iterator slí chun bailiúchán a thrasnú go seichimh gan a struchtúr inmheánach a nochtadh. Tá sé chomh bhunúsach sin go bhfuil sé ionsuite i bhformhór na dteangacha nua-aimseartha (for-of loops, iterators, generators).
Cad a dhéanann an patrún 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"
