O'Reilly logo

Design Patterns in Java™, Second Edition by William C. Wake, Steven John Metsker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

5 Composite

A COMPOSITE IS A group of objects in which some objects may contain others, so that some objects represent groups and others represent individual items, or leaves. When you model a composite, two powerful concepts emerge. One important 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 behaviors common to both individual objects and compositions. You can bring these ideas together by defining a common type for groups and items and modeling groups as containing a collection of objects of this type.

The intent of the COMPOSITE pattern is to let clients treat individual objects and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required