يوفر نمط 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"
