Iterator pattern จัดให้มีวิธี ท่องผ่าน (traverse) collection ตามลำดับโดยไม่เปิดเผยโครงสร้างภายในของมัน มันเป็นพื้นฐานมากจนถูกสร้างเข้าไปในภาษาสมัยใหม่ส่วนใหญ่ (for-of loops, iterators, generators)
Iterator pattern ทำอะไร
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"
