The purpose of the iterator design pattern is to grant access to an object's members without sharing the encapsulated data structures. There are two main motivations for using the iterator design pattern. First, not all object data is stored in the same manner. For example, an online store that aggregates content from other vendors might have a vendor that uses an array, another that uses a list, and a third that uses an ArrayList. A second reason is to avoid exposing data structures. Both the variability of storage approaches and data security can be addressed with the iterator design pattern.
The iterator design pattern is implemented by using the Iterator interface, part of the java.util package.
We will look at a simple use case, the UML class diagram, and the source code necessary to implement the iterator design pattern for this scenario.
...