Abstract
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 section of the book.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
To be fair, the begin()/end() duopoly is excessive; we could take a cue from Swift and define an interface with a single member such as: std::optional<T> next(). This way, you can just call next() until it gives you an empty value. Writing something like while (auto item = foo.next()) { ... }
- 2.
There is, of course, no --> operator; it’s quite simply the postfix decrement—followed by greater-than >. The effect, though, is exactly as the --> arrow suggests: in while (count --> 0) we iterate until count reaches zero. You can do similar tricks with “operators” such as <--, --->, et cetera.
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2018 Dmitri Nesteruk
About this chapter
Cite this chapter
Nesteruk, D. (2018). Composite. In: Design Patterns in Modern C++. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-3603-1_8
Download citation
DOI: https://doi.org/10.1007/978-1-4842-3603-1_8
Published:
Publisher Name: Apress, Berkeley, CA
Print ISBN: 978-1-4842-3602-4
Online ISBN: 978-1-4842-3603-1
eBook Packages: Professional and Applied ComputingProfessional and Applied Computing (R0)Apress Access Books