Pola Iterator menyediakan cara untuk melintasi koleksi secara berurutan tanpa mengekspos struktur internalnya. Pola ini sangat fundamental sehingga built-in di sebagian besar bahasa modern (loop for-of, iterators, generators).
Apa yang dilakukan pola 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"
