So I need to practice UML for a uni course and I can't figure out the following:
We need to make a UML Class diagram of a sports association. There is a player table. A sub-class of the player table is the referee table. A player is part of a team, and so is a referee (since referees are players also). A referee gets assigned to a match, but it can't be the match of his own team.
I can't find the answer to the last sentence. How do I put this in the UML Class diagram?
UML diagram is in Dutch. Wedstrijd = match, scheidsrechter = referee the others are not really necessary.
Your diagram has probably a couple of problems, because it says that for a competition (Wedstrijd
) there's only one Team
(composte aggregation) , which sounds neither competitive nor entertaining. Moreover it says that a club (Sportsverijn
) has at maximum one member, which doesn't fit with the narrative.
Once these problems solved (and a couple of others), and supposing that a Wedstrijd
involves two teams, you may add constraints to your model to express these complex conditions.
Typically, you would express them between curly braces, in plaintext: { cannot be referee for a match involving the relevant team }
next to the association between the match (Wedstrijd
) and the referee (Scheidsrechter
). This natural language constraint is ambiguous. A more formal expression could be written in OCL, something like: match.team->includes(match.referee.team) == false
The details of the expression will of course depend whether your model is a snapshot (seems to be the case here), or if it takes into account the fact that referees may change team in time. Here I have an alternative model that avoids composite aggregation and that associates referees to teams, with two examples of constraints: