-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Design Patterns and Best Practices in Java
By :
The iterator pattern is probably one of the most well-known patterns in Java. Some Java programmers are using it without being aware that the collection package is an implementation of the iterator pattern, regardless of the type of the collection: array, list, set, or any other types.
The fact that we can deal in the same way with a collection, regardless of whether it's a list or an array, is because it provides a mechanism to iterate through its elements without exposing its internal structure. What's more, the same unified mechanism is used by different types of collections. The mechanism is called the iterator pattern.
The iterator pattern provides a way to traverse the elements of an aggregate object sequentially without exposing its internal representation.
The iterator pattern is based on two abstract classes or interfaces, which can be implemented by pairs of concrete classes. The class diagram is as follows:

The following classes are used in...