0
votes

In UML class diagrams, I am told we should not have any standalone classes but that they should all be connected in some way. In theory that makes sense and with simple classes, sure.. take the following for example:

enter image description here

So, a Person can have 0 or more of Car... Fair enough.. but now take the following example:

enter image description here

The Person and PersonRepository are not really connected in the sense that a Person can belong to a PersonRepository or that a PersonRepository has a Person. They are associated in that the PersonRepository will return a Person for the given ID however. So, is it correct to add an association line between them and if so, which way should it point? I am getting conflicting info about this situation. I'd appreciate any clarification given on this.

1

1 Answers

0
votes

Usually, when instances of some class belong to instances of another class, it is an aggregation or composition relationship (which are special kinds of association).

If you can get a Person from a PersonRepository it is an association. Note that a repository may have more than one Person, so it has to be 1..n on the Person end.

An arrow on the association end represents that this end is navigable: you can go from instances of the class on the other end, to instances of the class in the end with an arrow. In your example, you can go from instances of Person to the PersonRepository (e.g.: person.getRepository()) but you cannot get instances of Person from the PersonRepository. The arrow should be on the other end.

        1..n     1
Person <----------- PersonRepository