The composite pattern
The composite pattern is used to model objects that can be grouped together and yet be treated the same as individual objects. This is not an uncommon case—for example, in a drawing application, we might be able to draw different kinds of shapes, such as circles, rectangles, and triangles. Every shape has a position and size so we can determine where they are located on screen as well as how large they are. When we group several shapes together, we can still determine the position and size of the large, grouped object. Additionally, resize, rotate, and other transformation functions can be applied to individual shape objects as well as grouped objects.
A similar situation happens with portfolio management. I have a retirement ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access