© The Author(s), under exclusive license to APress Media, LLC, part of Springer Nature 2022
D. NesterukDesign Patterns in .NET 6https://doi.org/10.1007/978-1-4842-8245-8_9

9. Composite

Dmitri Nesteruk1  
(1)
St. Petersburg, c.St-Petersburg, Russia
 

It’s a fact of life that objects are quite often composed of other objects (or, in other words, they aggregate other objects). Remember, we agreed to equate aggregation and composition at the start of this part of the book.

There are a few ways for an object to advertise that it’s composed of something. The most obvious approach is for an object to either implement IEnumerable<T> (where T is whatever you’re prepared to expose) or, alternatively, to expose public members that themselves implement IEnumerable<T> ...

Get Design Patterns in .NET 6: Reusable Approaches in C# and F# for Object-Oriented Software Design 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.