answersLogoWhite

0

Aggregation and composition are two sides of the same coin. Both an aggregate and a composite object encapsulate one or more sub-objects. But while a composite object owns its sub-objects, an aggregate object does not. That is, when a composite object is destroyed, its sub-objects are also destroyed. But with an aggregate object, the sub-objects are not destroyed.

Aggregate objects typically use references or pointers to refer to their sub-objects, whereas composite objects typically use member variables or pointers to refer to their objects. In essence, a composite object instantiates its own sub-objects, whereas an aggregate object's sub-objects must be passed to it, typically via the constructor.

In complex models you will often find a combination of composition, aggregation and inheritance, even within the same object.

User Avatar

Wiki User

11y ago

Still curious? Ask our experts.

Chat with our AI personalities

DevinDevin
I've poured enough drinks to know that people don't always want advice—they just want to talk.
Chat with Devin
LaoLao
The path is yours to walk; I am only here to hold up a mirror.
Chat with Lao
JudyJudy
Simplicity is my specialty.
Chat with Judy

Add your answer:

Earn +20 pts
Q: What is aggregation in C plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp