Allows you to compose objects into tree structures to represent part-whole
hierarchies. Composite lets clients treat individual objects and compositions
of objects uniformly.
Category:
Structural
UML Diagram:
Description of the Demonstration:
In this demonstration we are extending the demonstration from the Iterator Design Pattern.
The Menu class serves as the parent class for PancakehouseMenu, CafeMenu, and DinerMenu.
It is also the parent class of MenuItem of which each of the menus maintains a collection.
There are subclasses of MenuIterator for PancakehouseMenu, CafeMenu, and DinerMenu and
to maintain consistency there is also a MenuItemIterator. Now the Waitress can list
MenuItems individually or compositions of MenuItems in the same way.
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.