But you probably don't want to bloat the List interface with operations for different traversals, even if you could anticipate the ones you'll require. The Iterator pattern lets you do all this. The key idea is to take the responsibility for access and traversal out of the aggregate object and put it into an Iterator object that defines a standard traversal protocol. Whereas, a generic programming approach would only require four plus three configuration items. The Iterator provides ways to access elements of an aggregate object sequentially without exposing the underlying structure of the object.
Files are aggregate objects.
In office settings where access to files is made through administrative or secretarial staff, the Iterator pattern is demonstrated with the secretary acting as the Iterator. Several television comedy skits have been developed around the premise of an executive trying to understand the secretary's filing system. To the executive, the filing system is confusing and illogical, but the secretary is able to access files quickly and efficiently. Iterator can traverse a Composite. Visitor can apply an operation over a Composite.