bennji_of_the_overflow
bennji_of_the_overflow

Reputation: 1133

Is this relationship an aggregation, composition or something else?

Let's say I have the following relationship:

class A {
public:
   A(B& _objB);
   B& objB;
};

A::A(B& _objB)
 : objB(_objB) {}

This doesn't seem to fit with my understanding of the UML definitions of aggregation or composition. It feels like a composition, but in a composition the lifetime of the owned object should be tied to the parent object. In this case objB exists before A is created and after A is destroyed. A can't live without B, but B can live without A. This is the reverse of the standard composition relationship. Does that make it an aggregate or something else?

Upvotes: 6

Views: 348

Answers (1)

m_dunaevski
m_dunaevski

Reputation: 74

Already answered here , the answer is aggregation. a none owning usage of B.

Upvotes: 1

Related Questions