Iterator
Intent
Provide
a way to access the elements of an aggregate object sequentially without
exposing its underlying representation.
-Design Patterns, GoF
Structure
From
dofactory.com

Questions
1. What
different iteration techniques or methods could be effectively implemented
using the Iterator?
2. What
is polymorphic iteration?
3.
How could an Iterator be implemented with a
Composite?
4.
Does having an Iterator simplify or complicate an
aggregate data structure? When is one
helpful?
5. What’s
the difference between an Internal Iterator and External
Iterator? Under what conditions would you use each?
6.
How would you implement an internal iterator? Would you use reflection?
7. What
protection does a Robust Iterator give you?
8.
Should an Iterator be used to filter objects from a
list?
9.
What protection considerations are there between Iterators
and their aggregates?
10.
What is a Null Iterator?
Examples – Which are Iterator?
1. J2SE
Collection’s Iterator
Implement It!
Imagine
you have a Data structure to store an Employee.
If the employee is a manager, then (s)he has employees working
underneath him (i.e. association). Write
both an internal and external Iterator that can invoke
the following behavior:
1) Give all employees raises (i.e. employee.adjustSalary(1,000))
2) Notify all managers of a meeting (i.e. employee.notify(“meeting!”))
References
·
Iterator Design Pattern (Data & Object Factory)