Chapter 5. Composite
A composite is a group of objects in which some objects may contain others; thus, one object may represent groups, and another may represent an individual item, or leaf. When you model a composite, two powerful concepts emerge. One important modeling idea is to design groups so that they can contain either individual items or other groups. (A common error is to define groups so that they can contain only leaves.) A second powerful concept is to define common behaviors for individual objects and for compositions. You can bring these ideas together by defining a common type for groups and items and by modeling groups as containing a collection of objects of this type. This fulfills the intent of the COMPOSITE pattern: COMPOSITE ...
Get Design Patterns Java™ Workbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.