Definition
Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.. (implement methods to access to collection as a part of Aggregate class)
UML Class Diagram
Iterator: when and where use it
- A common programming task is to traverse and manipulate a collection of objects. These collections may be stored as an array, a list, or perhaps something more complex, such as a tree or graph structure. In addition, you may need access the items in the collection in a certain order, such as, front to back, back to front, depth first (as in tree searches), skip evenly numbered objects, etc. The Iterator design pattern solves this problem by separating the collection of objects from the traversal of these objects by implementing a specialized iterator class.
Sample
- Product
- Product Collection
- Client
Ref: Gang of Four tutorial
No comments:
Post a Comment