Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this relationship an aggregation, composition or something else?

Tags:

c++

uml

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?

like image 234
bennji_of_the_overflow Avatar asked Mar 14 '17 22:03

bennji_of_the_overflow


People also ask

Has a relationship composition or aggregation?

Aggregation relationship is also a "has-a" relationship. The only difference between Aggregation and Composition is that in Aggregation, objects are not tightly coupled or don't involve owning. All the objects are independent of each other and can exist even if the parent object gets deleted.

What is aggregation and composition with example?

Aggregation implies a relationship where the child can exist independently of the parent. Example: Class (parent) and Student (child). Delete the Class and the Students still exist. Composition implies a relationship where the child cannot exist independent of the parent.

What type of relationship is aggregation?

In UML models, an aggregation relationship shows a classifier as a part of or subordinate to another classifier. An aggregation is a special type of association in which objects are assembled or configured together to create a more complex object.

What is an example of aggregation?

Aggregation (also known as **containment) is a specialised form of association. It defines a one-way relationship that specifies a 'has-a' relationship between two classes. For example, you can say that a wallet has money. However, the money does not need a wallet in order to exist, so the relationship is one-way.


1 Answers

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

like image 82
m_dunaevski Avatar answered Oct 24 '22 10:10

m_dunaevski