user2158382
user2158382

Reputation: 4510

UML: 1-To-Many Relationship Representation?

I am new to UML, and I don't quite understand the notation yet.

enter image description here

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?

Upvotes: 2

Views: 10266

Answers (3)

Jim L.
Jim L.

Reputation: 6529

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.

Upvotes: 2

Gangnus
Gangnus

Reputation: 24464

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.

enter image description here

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.

Upvotes: 0

user3349359
user3349359

Reputation: 11

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.

Upvotes: 1

Related Questions