Electric
Electric

Reputation: 537

Confusion regarding association relationship in UML

To start off, I'm really confused between the association relationship between classes in UML, as there is unidirectional and bidirectional association.

I've drawn up a simple example, which is:

enter image description here

But I've looked up some examples online and i found out that most examples used the unidirectional association between the Patient class and the Doctor class.

When i interpret the diagram, i would interpret it as so where "the patient class knows about the doctor class but the doctor class does not know about the patient class." But it still didn't make much sense as in why would a doctor class not know about the patient class?

Could anyone please explain to me in a more detailed manner? It would be much appreciated.

Upvotes: 2

Views: 762

Answers (2)

Christophe
Christophe

Reputation: 73627

Interpretation of your diagram

Your diagram says that:

  • a Doctor can have several Patients, but has at least one (multiplicity 1..n)
  • a Patient can have several Doctors, and can have none (multiplicity 0..n)
  • a Doctor attends to a Patient
  • a Patient object can find the associated Doctor objects (navigability arrow at the end of the association)
  • nothing is said about whether a Doctor can find his/her Patients (absence of any navigability indication on the other end of the association). So we don't know

Potential problems in your diagram

First, there is an obvious confusion about where to place the multiplicity, because a newly appointed doctor may have no patient when he/she opens his/her practice. Conversely, a patient without any doctor is not a patient but a healthy person. So keep in mind that the multiplicity is next to the target: so 1..n is about the number of Patients for a Doctor and not the contrary.

Then the triangle near the label "attends to" indicates the sense of reading. Here it is Doctor attends to Patient. But in general, it's patient who attend to doctors. So the triangle should be on the other side and symetric to the one you have drawn.(sorry this last point was ok, I can still improve my english ;-)

The question of navigability

Now to the navigability. The diagram makes explicit that a Patient knows and can find the associated Doctors. In a hospital registration system, it makes sense when a patient arrives and doesn't remember the name of the doctor to lookup for the potential doctors.

But your diagram says nothing about the opposite navigability. This is left "unspecified". The diagram could clarify the situation either by indicating a cross on the link (i.e. no navigability), or an arrow (navigability).

Maybe there is a reverse navigability but it's not explicit (because the drawer assumed that it was so obvious). Maybe there is indeed no navigability in that direction. So the Doctor doesn't know its Patients. This could make sense for example if the hospital registration system consider that the Patient is the Patient of the hospital and the interaction has always to go via the administration. The Doctor may in such case have a navigable association to an Appointment that has a navigable association to the Patient or other kind of indirect navigability.

Upvotes: 4

Gerd Wagner
Gerd Wagner

Reputation: 5673

The terms "unidirectional association" and "bidirectional association" are not used/defined in UML. Rather, they refer to the way an association is implemented in OOP with either one reference property or a pair of mutually inverse reference properties (see also this tutorial).

In a conceptual model, we are not concerned with questions like "does the patient class know about the doctor class?". Rather, we just model the fact that there is an association between two classes.

The question if, with respect to an association between A and B, A "knows about" B is better formulated as: do instances of A need direct access to instances of B? In that case, we would add a reference property A::b for being able to directly access/retrieve all associated B objects. This can be expressed in a class diagram by placing a small dot at the B side of the association (called an "association end ownership dot" in UML).

It depends on the requirements of the app you are going to build if bidirectional access, which comes with a computational price, is really needed.

Upvotes: 0

Related Questions