Other Implementation Issues
Ordering components. In some programs, the order of the components may be important. If that order is somehow different from the order in which they were added to the parent, then the parent must do additional work to return them in the correct order. For example, you might sort the original collection alphabetically and return a new sorted collection.
Caching results. If you frequently ask for data that must be computed from a series of child components, as we did here with salaries, it may be advantageous to cache these computed results in the parent. However, unless the computation is relatively intensive and you are quite certain that the underlying data have not changed, this may not be worth the effort.
Thought Questions
A baseball team can be considered an aggregate of its individual players. How could you use a Composite to represent individual and team performance?
The produce department of a supermarket needs to track its sales performance by food item. Suggest how a Composite might be helpful.
Programs on the CD-ROM
Composite shows tree
\Composite\Composite
Composite that uses both child links and parent links
\Composite\DlinkComposite
Simple Composite of same employee tree that allows any employee to move from leaf to node
\Composite\SimpleComposite