2
votes

I'm trying to design a UML class diagram that represents Users that interact with other classes based on their roles, I've chosen to represent Roles as an enum class like so : user-role-class-diagram

What i'd like to represent is that only a user with a Role ADMIN can create a project, only a MANAGER can modify it and every CONSULTANT can only participate in it, can this be achievable with enum representation for Roles?

3
can i use uml constraints for that?mike_miu
"can i use uml constraints for that?" : yesbruno
but out of that your relation between User and RoleName is wrong, first there is no reason for a RoleName to know the Users (and an enum cannot do that) , so the relation must be directional (User ---> RoleName), and second using the multiplicity "" that means a given *User can have several roles, is it true ?bruno
@bruno yes you're right i'll modify the question and also i'll add my answer using uml constraints.mike_miu
Frankly speaking I you are not interested by my answer better I delete it being useless ...bruno

3 Answers

0
votes

A solution is to use uml constraints like so:

solution

0
votes

Being an enumeration RoleName is better drawn with <<enumeration>> (like in the Figure 7.1 - Class Diagram Example page 7 of Object Constraint Language - formal/2014-02-03 )

If Role is only an envelop for RoleName that class is useless (this is what I suppose in the diagram below)

The relations create, manage, participate do not represent attributes, the multiplicities have non sense in that context. The relation role has the default multiplicity 1

Your constraints are pre-conditions, their context is the class User and in OCL the equality operator is "=", so your diagram can be :

enter image description here

0
votes

You are mixing static representation and behavior. The User has one association to Project (not 3 different ones):

enter image description here

The different behavior (derived from some UC) can be shown in a collaboration. E.g. in an AD like this:

enter image description here

Just a sketch, but that should give you the gist.