© Dmitri Nesteruk 2022
D. NesterukDesign Patterns in Modern C++20https://doi.org/10.1007/978-1-4842-7295-4_8

8. Composite

Dmitri Nesteruk1  
(1)
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 very few ways for an object to advertise that it’s composed of something. Fields, by themselves, do not constitute an interface unless you make virtual getters and setters. You can advertise classes as being composed of a collection of objects by implementing begin()/end() members, but keep in mind that this doesn’t actually state a lot: after all, you can ...

Get Design Patterns in Modern C++20: Reusable Approaches 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.