-1

There are three types of roles in a system.

Referees

President (There will be only 1 president)

Authors

A person can be both a referee and a author.

If a person has the role of President, they cannot have another role.

How should a UML Class diagram be?

  • 1
    @Rasit Hello and welcome! Your question is interesting. However to provide you a more specific answer, we’d need to know what you want to do with the roles in your system, if the president is unique across the whole system, how probable it is for the roles to evolve (e.g. adding more roles such as co-author, publisher, auditor, vice-president, etc), and if roles are associated with behaviors. Could you edit your question accordingly? – Christophe Jan 27 '21 at 17:36

2 Answers2

2

It all depends on the purpose of persons and roles in your design.

As a first thought, if a Person can have a Role, you’d have here two classes with an association with the following multiplicities:

  • a Person has 1..n Role, meaning at least one role
  • a Role can be taken by 0..n Person, which means that there are roles which might not be fulfilled at all, and roles that can be held by several users
  • nothing is said about the specific number of occurrences of the association (called links) for a specific occurence of a class (called object, e.g. a labelled as “president”)

For the specific roles such as “president”, there are number of design options:

  • you could have(hard-coded?) controls in your system that ensure there is only one link. You could express this in a class diagram with an explicit constraint.
  • you could specify the maximum number of persons having the role as a property of the role. But this immediately suggests that there are different kind if roles (some with a maximum, some without limits).

A deeper look on this start model raises other questions:

  • Is this limit of 1 president global for the system, or if the role are associated with something else (e.g. president of an entity, a jury, a company...)? In the later case, some additional classes (and requirements) would be missing.
  • Is the list of roles fixed and are there a lot of rules associated with them? If yes, you could think of an enum as suggested by Bruno. If not you could just think of a string property to describe the role.
  • Last but not least, do specific roles have specific behavior in the system? If yes, you could think of adding specialization of roles in your diagram (and President would be an obvious candidate for being such a specialization of Role).

So it all depends on the larger picture of your design.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • 1
    of course when I answer I also think about classes/interfaces but did not mention that because as you say first that supposes to be 'interesting' to have specific behaviors which are not part of the statement, and to really answer to the constraints (except 1 President) to have the classes President Author Referee and AuthourReferee :-( I mean to just say there is a class President is not enough to be a solution, I think you need to say more – bruno Jan 27 '21 at 16:22
  • 1
    @bruno I can guarantee you that I didn’t DV your answer. On contrary! I admire your mastery of constraints. And while I was at first surprised by your enumeration due to my personal experience with roles, I finally got your point and acknowledged your position in my answer. Obviously OP’s design intent was missing, so I tried to give some guidance with possible alternatives. I hope it was clear enough without being too boring. – Christophe Jan 27 '21 at 17:19
  • @Christophe be sure there is absolutely no problem, and I admire a lot your answers which are so clear in a general way, with an editorial quality I will never reach. This is why I taken the liberty to say for one time may be you can say more, but of course this is just a suggestion. Cheers – bruno Jan 27 '21 at 17:23
0

In your question I suppose

  • the role Referees must be Referee

  • the role Authors must be Author

  • If a person has the role of President, they cannot have another role must be If a person has the role of President, that person cannot have another role

  • there will be only 1 president must be there is 1 and only 1 president

A way to model that in UML is :

enter image description here

Thanks to the multiplicity 1..2 {unique} a Person has 1 or 2 roles and cannot have two times the same role.

But the multiplicity allows to be both a referee and a president or an author and a president, this is why I added the constraint self.roles->size() = 1 or self.roles->excluding(Role::President) on Person to avoid that.

Thanks to the constraint Person.allInstances()->count(p | p.roles()->first() = Role::President) = 1 there is one and only one president. Or course if it is possible to not have a president replace = 1 by <= 1

About the multiplicity see § 7.5.3.2 Multiplicities from page 33 and § 7.5.4.1 Multiplicity Element from page 34 of formal/2017-12-05

About OCL, see formal/2014-02-03

bruno
  • 32,421
  • 7
  • 25
  • 37
  • Answering based on pure assumptions is not really an answer. – qwerty_so Jan 27 '21 at 17:01
  • 1
    @qwerty_so where do you see assumptions ? the typos corrections ? or because the natural language is not formal and then by 'definition' we always make assumption from **all** the questions on S.O. ? Of course in the last case *all* the answers must be deleted and then S.O. banned. Please be more precise than it is the case in your remark ... else I can only do assumption when I read it – bruno Jan 27 '21 at 17:07
  • 1
    @qwerty_so isn’t the only “assumption” in Bruno’s answer in reality a diplomatic and polite way to draw attention at typos and grammar issues in the question? – Christophe Jan 27 '21 at 17:28
  • @Christophe The question is by far not clear. Answering on an unclear question is questionable (pun intended). _"In your question I suppose"_ clearly states that the answer is based on assumptions. – qwerty_so Jan 27 '21 at 18:27