Bird
Raised Fist0

Why does the Iterator pattern separate traversal logic from the collection itself?

hard🧠 Conceptual Q10 of Q15
LLD - Behavioral Design Patterns — Part 1

Why does the Iterator pattern separate traversal logic from the collection itself?

ATo enforce a single traversal order for all collections
BTo improve the collection's internal data structure performance
CTo prevent any modification of the collection during iteration
DTo allow multiple traversal strategies without changing the collection
Step-by-Step Solution
Solution:
  1. Step 1: Understand separation of concerns in Iterator pattern

    The pattern separates traversal logic to allow different ways to iterate without modifying the collection.
  2. Step 2: Analyze options for correctness

    To allow multiple traversal strategies without changing the collection correctly states this benefit. B is unrelated to traversal logic, C is about modification control, A is false as multiple orders are possible.
  3. Final Answer:

    To allow multiple traversal strategies without changing the collection -> Option D
  4. Quick Check:

    Separation enables flexible traversal strategies [OK]
Quick Trick: Separate traversal to support multiple iteration ways [OK]
Common Mistakes:
MISTAKES
  • Thinking Iterator improves data structure speed
  • Assuming Iterator enforces single traversal order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More LLD Quizzes