Armada
Armada

Reputation: 728

Do pointer/reference data members indicate an association or aggregaation relationship in UML?

I'm a bit confused about which one it is.

You could say it 'uses' the object via the pointer - therefore association. But it also sounds like aggregation - 'has an' object but when this object dies that doesn't mean the referenced object dies.

Which one makes most sense in UML?

Upvotes: 2

Views: 956

Answers (2)

vainolo
vainolo

Reputation: 6987

It can indicate association, aggregation and event composition. The difference between the three is semantic and not static or implementation specific.

  1. If the pointed class has a lifecycle dependency with the owning class (a part of a whole that cannot exist without it, like entry classes in a hashmap) then it is a composition.
  2. If the pointed class is a part of the owning class (semantic relation, i.e. a database connection that is shared between controllers in an application) then it is an aggregation.
  3. If the pointer class is used for another thing (caching, intermediate values in some calculation, etc) then it is probably a simple association.

But UML leaves a LOT of space for different interpretations, so you will never get a "correct" answer here.

Upvotes: 1

Javier
Javier

Reputation: 12398

First, an "aggregation relationship" is actually a (binary) association where one end has an aggregation kind other than "none". Then aggregations are just associations with refined semantics.

Aggregations can be composite (full diamond) or shared (hollow diamond). A composite aggregation means that "the composite object has responsibility for the existence and storage of the composed objects" (then the referenced object dies when the composite is deleted, but a part may be removed before the composite is deleted).

A shared aggregation, on the other hand, does not tie the lifecycle of the aggregated object (the UML specification says that "precise semantics of shared aggregation varies by application area and modeler" and "the precise lifecycle semantics of aggregation is a semantic variation point"). They are something in the middle between an unadorned association and a composite one.

Upvotes: 1

Related Questions