CLOSE
Updated on 27 Jul, 20252 mins read 84 views

The Iterator Design Pattern is a behavioral design pattern that provides a way to access elements of a collection sequentially without exposing the underlying representation (e.g., array, list, tree).

Intent

  • Decouple the collection from the algorithm used to traverse it.
  • Provide a unified interface for traversing different types of collections.

Key Components

  1. Iterator Interface: Defines methods for traversing a collection (e.g., next(), hasNext()).
  2. Concrete Iterator: Implements the iterator interface for a specific collection.
  3. Collection Interface: Declares a method to return an iterator object.
  4. Concrete Collection: Implements the collection interface and returns a concrete iterator.

Leave a comment

Your email address will not be published. Required fields are marked *