Moulie415 Moulie415 - 6 months ago 64
Java Question

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

If you want to show, for example, that a class

contains an instance of class
and class
, 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
is created then that also creates an instance of

Here's what I mean in code:

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



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.