Loop Iterators

Whenever you have collections, a problem that arises is how to provide access to the elements of a collection without revealing the inner working of the data structure. A popular solution in object-oriented languages is the idea of an iterator, sometimes called an enumerator.

An iterator is a facilitator class that provides access to the elements of a collection. The next slide shows how iterators are used. The iterator is a high level abstraction, and so the user need not be aware of the implementation details for the collection.

The iterator itself, however, is privy to these details, and thus must work closely with the original container class.

[audio] [real] Text to accompany slide11, in Chapter 8 of An Introduction to Object-Oriented Programming