The purpose of the iterator pattern is to run through a collection of data. The pattern itself consists of two primary classes: The Aggregate class, and the Iterator class. The Aggregate class is the class which we want to run through for specific data. The Iterator class contains the method to run through the Aggregate class.
In a typical library one of the challenges is organizing a large amount of books and finding the correct ones for the customers. When the books add up to a significant amount it can be hard to find the right one. Luckily, we got an experienced librarian, who has a system of finding any book by title, ID or any other information. Compared to the iterator pattern, the library is the Aggregate class, books are the element in the Aggregate class, and the librarian is the Iterator classs that runs through the elements of the Aggregate class.
A large sales company has problems maintaining its data of customers and products. They require an IT company to run through the data and find the correct ones in the given situation. When the sales company require a specific file they call the IT company to find the specific data. In this example, the sales company acts as the Aggregate class, the customer and products data is the elements in the Aggregate class, and the IT company acts as the iterator class which searched through the data contained by the sales company.