问题
I am new to UML, and I don't quite understand the notation yet.
This is my understanding of the diagram.
The system has many doctors. Doctors can have many patients; however, patients can only have one doctor. Therefore this is a **One-To-Many** relationship
However, I feel like this can also be interpreted as...
The system has 1 doctor. That one doctor has many patients.
Which is the correct interpretation and why?
回答1:
To put it simply: your first interpretation is correct. Each Doctor
is associated with many Patients
. Each Patient
is associated with one Doctor
. The multiplicity of 1
tells you only how many Doctors
are associated with each Patient
, not how many are in the system. Understand that a class usually represents a set of many instances.
BTW, for an analysis model, you should use association-end names to give these associations semantics. For example, each Doctor
treats many Patients
. Each Patient
is treated by one Doctor
. The semantics will expose whether your model is correct for the business domain. Without semantics, the relationship could represent billing, treatment, visits at the hospital, etc. The treats goes on the end with the *
, and the is treated by goes on the end with the 1
.
For a lower-level model, you should replace treats with treatedPatient and replace is treated by with treatingDoctor.
回答2:
Lets say your system is a hospital, clearly more than one Doctor should be allowed to work at the hospital so the most correct interpretation is the 1st.
回答3:
The association line on the diagram shows one association. There could be many associations, or none of them, that doesn't matter. We are speaking on one concrete association:
a doctor can have many patients.
So, your second interpretation is also correct, but it speaks on ONE exemplar of associations only.
If we'll recall, that the number of associations is arbitrary, for the whole system we are having the first sentence.
An association can be realized so, that every patient will have a reference (possibly null one) to a doctor. We could realize it as a list of patients for every instance of doctor. Or both - for easier search, for example. But all this information speaks only about ONE relationship - one doctor to many patients.
Notice, that there could be 2(or more) such relationships. For example, a doctor had visited today some patients. It is the relationship that we'll name DoctorIsActive. And the other one - doctor was visited by some patients. It will be another relationship, PatientIsActive. So, we'll have two lines connecting these blocks, with different names on them, both one-to many. But we don't have two doctors because of it. It could be even more complicated - for example, a doctor can make on operation a day.
Don't be ashamed - I had sometimes the same problem with understanding this fact, too. And as I know, it is very widespread misreading.
Look here for more info on associations.
来源:https://stackoverflow.com/questions/22003666/uml-1-to-many-relationship-representation