Summary
The intent of the ITERATOR pattern is to let a client access the elements of a collection sequentially. The collection classes in the Java class libraries offer rich support for operating on collections, including support for iteration. These iterators usually require a client to cast the returned objects to the appropriate type. You can strengthen your contract with clients by creating type-specific collections with type-specific iterators.
If you create a new type of collection, you will often want to create an iterator to go with it. Domain-specific composites are a common example of a new collection type. You can design a fairly generic iterator for composites that you may be able to apply against a variety of composite hierarchies. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access