31. Composite

image

© Jennifer M. Kohnke

A composite is a euphemism for a lie. It’s disorderly. It’s dishonest and it’s not journalism.

—Fred W. Friendly, 1984

The COMPOSITE pattern is a very simple pattern that has significant implications. The fundamental structure of the COMPOSITE pattern is shown in Figure 31-1. Here, we see a hierarchy based on shapes. The Shape base class has two derivative shapes: Circle and Square. The third derivative is the composite. CompositeShape keeps a list of many Shape instances. When called on CompositeShape, Draw() delegates that method to all the Shape instances in the list.

Figure 31-1. COMPOSITE pattern

Thus, ...

Get Agile Principles, Patterns, and Practices in C# now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.