Introduction to OOP Chapter 24: Design Patterns : next previous audio real text

Iterator

Problem: How do you provide a client access to elements in a collection, without exposing the structure of the collection.

Solution: Allow clients to manipulate an object that can return the current value and move to the next element in the collection.

Example, Enumerators in Java

interface Enumerator {
	public boolean hasMoreElements();
	public Object nextElement();
}

Enumeator e = ...;
while (e.hasMoreElements) {
	Object val = e.nextElement();
	...
}
The pattern applies, even if the interface is changed.
Intro OOP, Chapter 24, Slide 08