Corak Iterator menyediakan cara untuk merentasi koleksi secara berurutan tanpa mendedahkan struktur dalamannya. Ia begitu asas sehingga terbina dalam kebanyakan bahasa moden (gelung for-of, iterator, generator).
Apa yang dilakukan oleh corak 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"
