3

I was wondering, are these 2 class diagrams equivalent EXCEPT the fact that in diagram A, a student doesn't have to have a study program?
The way I see it - for example in diagram B a study program can have many students, and for each one of them, an enrollment is created. Diagram A states that for each pair (Study Program, Enrollment) exists one student, so this could also convey the idea that a Study Program has many students, and for each one exists an enrollment.
The difference between these cases could be that in diagram A, a student may exist on its own, while in diagram B it needs to have at least one study program (and consequently an enrollment as well).
Is my logic correct here?

A)

enter image description here

B)

enter image description here

1 Answer 1

2

Your assumption is correct.

Quotes from the UML 2.5 specification:

For an Association with N memberEnds, choose any N-1 ends. Let the Property that constitutes the other end be called oep, so that the Classifiers at the chosen N-1 ends are the context for oep. Associate specific instances with the context ends. Then the collection of links of the Association that refer to these specific instances will identify a set of instances at oep. The value represented by oep is a collection calculated from this set as follows: All of the instances in the set occur in the collection, and nothing else does. The cardinality of this collection is its size. The multiplicity of oep constrains this cardinality.

The following quote is especially interesting for your example:

A lower multiplicity for an end of an n-ary Association of 1 (or more) implies that one link (or more) must exist for every possible combination of values for the other ends.

So, your ternary association defines the following business rules:

  • For every combination of Study Program and Student, there is exactly one Enrollment.
  • For every combination of Study Program and Enrollment, there is exactly one Student.
  • For every combination of Student and Enrollment, there is exactly one Study Program.

All these business rules also apply to diagram B. But diagram B defines an additional rule: Every Student is associated to at least one Study Program (1..*).

2
  • I saw that question, but there seems to be a disagreement between the answerers. For example, the last answer in that post reinforces my statement (I think) by stating that a multiplicity in a ternary association only regards pairs of the other 2 classes, while the first answer has your opinion. Maybe it is just unspecified...
    – erap129
    Commented May 3, 2019 at 7:01
  • You are right. I have digged into the UML spec and now I see my answer was completely wrong. I have rewritten it. Commented May 3, 2019 at 7:26

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.