Wzorzec Iterator zapewnia sposób na przechodzenie po kolekcji sekwencyjnie bez ujawniania jej wewnętrznej struktury. Jest tak fundamentalny, że jest wbudowany w większość nowoczesnych języków (pętle for-of, iteratory, generatory).
Co robi wzorzec 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"
