Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show instance of class within a class in UML?

Tags:

java

uml

If you want to show, for example, that a class Match contains an instance of class Game and class Set, then do you just simply have them in the attributes or do you have a line to the classes representing that when the instance of Match is created then that also creates an instance of Game and Set?
Here's what I mean in code:

public class Match {
    private Set set = new Set();
    private Game game = new Game();

}
like image 452
Moulie415 Avatar asked Dec 15 '22 02:12

Moulie415


1 Answers

This kind of relationship between classes is called association. Association is marked in UML with simple arrow:
enter image description here

We also have to types of association:

   1. Composition - when our class contains reference to the other class and other class cannot exist without our class.
For example Human contains Hand, Leg, Heart, Car conatins Engine, Wheels.
This type of association is understood as strong reference in garbage collection programming languages.
enter image description here

   2. Aggregation - when our class contains reference to the other class and other clas can exist without our class, for example School contains Student.
This type of association is understood as weak reference in garbage collection programming languages.
enter image description here

Composition is definetly the stronger one.
Hope it helps.

like image 112
Michał Szewczyk Avatar answered Dec 16 '22 16:12

Michał Szewczyk