Provides a way to access the elements of an aggregation object sequentially without
exposing its underlying representation.
Category:
Behavioral
UML Diagram:
Description of the Demonstration:
In this demonstration the Waitress class must list all of the
MenuItems in both the PancakehouseMenu and the CafeMenu. Each
menu however stores its' instances of MenuItem in a different way.
To avoid tightly coupling the Waitress class to the menu classes
an appropriate subclass of MenuIterator is provided to the Waitress.
The Waitress does not need to know how to iterate over each of the
different types of menu storage objects, she can just call the Iterator
getNext function to get the next MenuItem in its collection and hasNext
to see if there is still another MenuItem not accessed. Iterator is
the one Design Pattern that is implemented in all of the collection
classes of the Standard Template Library.
Code:
Click here to download a
zip file containing all the source files and an executable of the
Demonstration. See the _ReadMe.txt file in the zip.