Iteratorパターンは、コレクションの内部構造を公開せずに**順序立ってトラバース(走査)**する方法を提供します。これは基本的なパターンなので、ほとんどの現代的なプログラミング言語に組み込まれています(for-ofループ、イテレータ、ジェネレータ)。
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"
現代的な言語に組み込まれている
( item collection) { }
* () { ( i = ; i < n; i++) i; }
( i ()) .(i);
