Iterator pattern ایک collection کو ترتیب سے traverse کرنے کا طریقہ فراہم کرتا ہے بغیر اس کی اندرونی ساخت کو ظاہر کیے۔ یہ بہت بنیادی ہے کہ یہ زیادہ تر جدید زبانوں میں built-in ہے (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"
