[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
CppComposition
Differs from ?aggregation that the members of the composition will be destroyed if the composition is destroyed. In an ?aggregation, the members can remain in memory.
For example: making the class Engine a member of the class Car.
Prefer composition to inheritance [1].
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
CppComposition
(C++) Composition
Make a class a member of another class to mimic a 'HAS-A' relationship between the two classes. To model a 'IS-A' relations use inheritance.Differs from ?aggregation that the members of the composition will be destroyed if the composition is destroyed. In an ?aggregation, the members can remain in memory.
For example: making the class Engine a member of the class Car.
Prefer composition to inheritance [1].
Reference
1) Herb Sutter and Andrei Alexandrescu. C++ coding standards: 101 rules, guidelines, and best practices. ISBN: 0-32-111358-6. Chapter 34: 'Prefer composition to inheritance'.[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
