Το pattern Iterator παρέχει έναν τρόπο να διασχίσετε μια συλλογή διαδοχικά χωρίς να εκθέσετε την εσωτερική της δομή. Είναι τόσο θεμελιώδες που είναι ενσωματωμένο στις περισσότερες σύγχρονες γλώσσες (for-of loops, iterators, generators).
Τι κάνει το 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"
