1

The answer to this question is A however I can't wrap my head around how there is a inheritance given the only information is the quote below (ie. a player is not a kind of team). It would make more sense to me not assume a inheritance, and just go with B where there is a simple association. Possibly the answer key is wrong? Also this is not the actual question, i modified it such that it wouldn't break any rules.

How would you model this situation with a class diagram? Each team has many players, and each player can play only in one team.

enter image description here

9
  • 1
    The arrow isn't an inheritance arrow, but a unidirectional association. Inheritance arrows have outlined tips and a different shape (triangular, not pointy). You can see both types in this diagram for comparison: researchgate.net/figure/…
    – Polygnome
    Commented Apr 1, 2022 at 22:32
  • Thanks, but shouldn't the question explicitly allude to a unidirectional association if thats the case? (ie. team class has a method that calls on player, and not vice versa?)
    – moo
    Commented Apr 1, 2022 at 22:43
  • I don't see any methods in the two diagrams, at all. Since you said this is not the actual question, I'M getting the feeling that something is "lost in translation" while you tried to re-create the question here.
    – Polygnome
    Commented Apr 1, 2022 at 22:50
  • Thats the thing, there isn't any methods listed. The only words I changed in the question are the class names (team and player). Everything thing else is the same.
    – moo
    Commented Apr 1, 2022 at 22:55
  • 1
    Well, you introduced methods in your previous comment, so I was wondering how you got the thought that there should be any. You don't need methods to describe relations between objects. Associations are most oftenly implemented with fields, and in case of n-ary relations, with some form of collection in the language you are using (or set, or list, depending on the exact semantics needed).
    – Polygnome
    Commented Apr 1, 2022 at 22:59

1 Answer 1

2

The answer key is wrong if the diagram is supposed to match exactly the narrative.

The narrative only provides information about two classes, Team and Player, an association between the two, and the multiplicities at the association ends, i.e. 1 and 1..*. The diagram B corresponds exactly to that narrative.

The diagram A adds some navigability that cannot be inferred from the narrative. It says that at runtime a team instance can easily find the associated player instances. It is not necessarily unidirectional: the other end has an unspecified navigability. Absence of navigability from the other end (i.e truly unidirectional) would be shown explicitly with a cross.

The navigability arrow should not be confused with inheritance. To avoid such confusion, the UML specifications mandate an open arrow for navigation, and a large hollow triangle as arrow head for inheritance. (Your diagram uses a small plain arrow head. It’s too small for inheritance, but small open could have prevented any confusion).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.