W4: Compositions, Aggregations and Associations Flashcards
A composition is…
a strong relationship: the composer object owns the component object: one class completely contains another class and determines its lifetime.
An aggregation is…
a weaker relationship: the aggregator has an instance of another class, which determines its own lifetime.
An association is…
the weakest relationship of the three: one class accesses or uses another class: neither class exhibit a ‘has a’ relationship to the other class.
Compositions, aggregations, and associations appear in classes with _________
resources
If a class with a resource is responsible for copying and destroying its resource, then that class is a composition. If the class is not responsible for copying or destroying its resource, then that class is an aggregation or an association.
A composition is a ____ relationship between classes.
has-a
A composition can be implemented in 2 ways:
a sub-object or a pointer to the sub-object
ex.
Name name; // sub-object
OR
Name* name {nullptr}; // pointer
In an aggregation relationship, the aggregator ____ the aggregatee.
uses
The aggregator is complete whether or not any of the objects that it uses exist.
Does the aggregator create and destroy the objects it uses?
No, the aggregator is not responsible for creating and destroying.
Association does not involve any _______ of one type by another.
ownership
Each type is independent and complete without any related type.
If one object of an association is destroyed, is the other object destroyed as well?
No, they exist independently.