Iterator pattern किसी collection को उसकी internal structure को उजागर किए बिना क्रमिक रूप से traverse करने का तरीका प्रदान करता है। यह इतना मूलभूत है कि यह अधिकांश आधुनिक languages में 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"
