UML Domain model - how to model multiple communication roles between two objects?

Assume that there is a scenario for users with tasks. Each User can be either an Observer or a Task Worker.

In addition, a worker can record hours of work that he worked on a task.

Will the following chart be correct? I looked at the domain models and I did not see one with two associations (works on, clock). It is acceptable?

enter image description here

EDIT: How about this scenario? The user can make an offer to another user. A possible way to model it is shown in the following diagram.

However, in this diagram, the user can make an offer to himself. Is it possible to simulate some constraints in or process them further along the development line?

enter image description here

+5
source share
3 answers

In principle, this is correct, as you model the plural relationships between two classes.

Regarding limitations, UML uses OCL (Object Constraint Language), so you can say that associations are exclusive (xor - exclusive or).

Also note that it is generally recommended to specify the final roles of associations.

enter image description here

Regarding one of the comments saying

There is no UML police that would prevent you from being unacceptable.

It's how to say: there is no police police to tag you for writing shitty code.

You create diagrams for conveying information (for a school project anyway), if you deviate from standards or best practices, you make it difficult for other people to understand your diagrams.

And just as there are sheets (jslint, ...) that check your code for common problems, for models there are models that do the same.

Also, models, like code, are not installed in stone, so do not be afraid to modify them when you find the best way to express your domain.

Update

As Jim accurately noted, you usually do the material not as a User (or Man), but as a role. For instance. when you are a student, and you fill out the form, no one cares that you are people, but that you are a student. As a rule, a person will also have several different roles (you can be a Student and TP, Professor, etc.).

Separating it this way makes the domain more understandable, since you are only concerned about the roles, not the people who implement them.

enter image description here

+5
source

On the first model there is nothing to add after Peter an excellent and very interesting answer.

However, your second diagram (in the editing section) seems to give a true and fair view of the story. From a strict relationship of 1 to 1, I would understand that each user makes one offer to one other user, and each user receives exactly one offer from another user:

  • "A user can make an offer to another user" implies a power of 0..1 or *, not 1.
  • From this we understand implicitly that not all users should receive an offer, i.e. also quantity 0..1 or *
  • This can be discussed, but the β€œ proposal ”, in my opinion, does not mean β€œthe biggest offer”, so the upper limits of the power should not be * , but not 1, to show that each user can make several offers and get several offers.

enter image description here

As you can see, you can add constraints to the circuit to increase expressiveness. This is done in the annotation between { } . But you can choose the most suitable syntax. Here is an example with the full expressiveness of natural language (as suggested by Martin Fowler in his "UML distilled"), but you can, of course, use a more formal OCL by making it {self.offerer<>self.offeree} .

+3
source

I see that @Peter updated his answer before I could post this answer, but I will post it anyway to show you other tricks.

In general, it is fair to have multiple associations between the same two classes. However, I do not think this is a good idea.

You say you want to create a domain model [problem]. I am glad to hear it! The problem domain model is very important, as I explain in the last paragraph here . It's one thing to note that you want to build a solid model that goes beyond the scope of the system you can imagine. There is no "User" in the problem area. However, there are roles that people play. For example, you mentioned the Supervisor and the Worker. I hope these are the concepts that your client already has in the "meat world".

In the model you published, you have nowhere to hang hours of work or progress. You can try the exercise. If you didn’t have a computer, how would your client track these things? They often had (or had) a way, and this was probably quite optimal for a manual system.

Here's how I can model my understanding of your problem area:

enter image description here

Some notes:

  • A person plays any number of roles.
  • A role refers to one Task and one Person. The observer observes exactly one task, the worker is assigned exactly one task, and exactly one Person plays any role.
  • A role is abstract, and its subclasses are {complete}, that is, there cannot be a real instance of a role without being also an instance of a subclass.
  • Each observer is monitored and can be assigned to one Employee at a time. There is a limitation saying {the person is not an observer}. (You can show OCL for this, but few will understand it.)
  • I added the concept of Progress as a way of recording progress in a task. An employee advances in one task. Each Progress bit has a description and duration. Please note that I did not perform any computational way of presenting a description or duration. The system developer for this will be free to get the Duration from the beginning and end, or ask the user to report independently.
+1
source

Source: https://habr.com/ru/post/1245378/


All Articles