Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uml class diagram - when should use usage, aggregation or association?

Tags:

uml

I am brand new in UML desgin. Here, I have a question about it. Let us say I have two class, one is main caller class A, and it will new another class B. Should I use usage to represent the relationship between A and B (or aggregation)? Moreover, if a class C calls a method in another class D. What should I use? Association? or usage? Please help. Thanks a lot.

like image 642
Laodao Avatar asked Dec 20 '22 16:12

Laodao


2 Answers

Dependency is the most abstract among all relationships. Between 2 classes it only means that one is somehow "aware" ot another. Example: An object of a class A receives a reference to an object of the class B (during some method execution) and do something with it (like calling its method). Usage is a special type of dependency and means that class A uses class B.

Association is somehow stronger relationship than dependency. Example: A class a has a member (attribute) of class B and permanently holds this reference. The difference from the previous example is that this link is long-term, versus short-term link expressed through dependency.

Agregation and compositions are also associations, but stronger ones. Their semantics depends on the implementation language or context. Agregation is a non-exclusive relationship of the type Group-Member (several Members belog to the same group and can also belong to other groups). When Group is destroyd - Members are just unasigned from it and not destroyd. Composition is exclusive and very strong relationship: Whole-part. Part is under total control of Whole - is practically part of it. Without the Whole, the Part does not exist, so when the whole is destroyed, the Part will die as well.

like image 96
Aleks Avatar answered Jan 02 '23 09:01

Aleks


In UML, a Usage is a special type of Dependency in which one model element (e.g. an operation in class C) requires another model element (e.g. an operation in class D) for its "full implementation or operation". Thus, there is a usage dependency of your class C on your class D, but no association.

I have explained how to use associations in design models in my tutorial Managing Unidirectional Associations in a JavaScript Frontend Web App.

like image 25
Gerd Wagner Avatar answered Jan 02 '23 08:01

Gerd Wagner