Iterator Pattern

Context

  1. An aggregate object contains element objects
  2. Clients need access to the element objects
  3. The aggregate object should not expose its internal structure
  4. Multiple clients may want independent access

Solution

  1. Define an iterator that fetches one element at a time
  2. Each iterator object keeps track of the position of the next element
  3. If there are several aggregate/iterator variations, it is best if the aggregate and iterator classes realize common interface types.


previous | start | next .... [Slide 11] ....