Moulie415 Moulie415 - 27 days ago 19
Java Question

How to show instance of class within a class in 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();

}

Answer

Both listing as attributes and showing as association (line pointing to another class) are valid and have exactly similar semantic.

Showing graphically rather than textually gives you opportunity to optionally present additional information: aggregation/composition, availability, ownership. Yet if none of this is present or important, the meaning is precisely the same and one can be replaced with another depending on what is more useful for you.