4.11. Data Member Objects
Object-oriented programming and design promote class reuse. This concept is central to the idea of “layering” software; that is, defining new classes in terms of existing classes that already work. One method of code reuse is containment, where the data members of one class are objects of a different class.
Containment offers several advantages to class designers.
Containment hides the implementation details of data member objects. Changes to the inside view of a data member object will not affect the implementation or interface of the class that contains it.
The compiler creates and deletes data member objects automatically, calling constructors and destructors as needed (the containing class may need to supply constructor ...
Get Navigating C++ and Object-Oriented 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.