2

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.

Electric
  • 517
  • 11
  • 25

2 Answers2

4

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.

Christophe
  • 68,716
  • 7
  • 72
  • 138
  • 1
    very nice and complete answer! – Geert Bellekens Mar 21 '19 at 09:20
  • 1
    I agree, that this is a very complete answer. As a matter of fact you use the same elements/connectors in different detail during design phase. The OP's diagram looks like being in earlier design phase. So what needs to be said (direction, ownership, role names, multiplicity, etc.) also strongly depends on the design phase itself. Just as a thought. No need to expand on the answer as this will lead to just another UML book ;-) – qwerty_so Mar 21 '19 at 20:06
0

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.

Gerd Wagner
  • 5,481
  • 1
  • 22
  • 41
  • 2
    The unidirectional/bidirectional refers to the navigability, which **is** defined in UML. Since v2.5 they also added the dot notation to indicate whether or not there is a property referencing the other side, but these are two different things. In this case the question is about navigability (arrowhead), not about referencing properties (dot notation) – Geert Bellekens Mar 20 '19 at 09:29
  • Concerning your first claim: just search in the spec - they do not even mention the terms "unidirectional" and "bidirectional"! Concerning your second claim: the question is not about navigability, but about which class "knows about" the other one. – Gerd Wagner Mar 20 '19 at 12:33
  • Yes, but these just common vocabulary to indicate the direction of arrows. I think OP is asking about navigability, not the dot notation. – Geert Bellekens Mar 20 '19 at 12:35
  • @GeertBellekens Given what OMG says about DirectedRelationship on p.42 I'd concur with the statement that "it's not defined". It totally leaves open what the "Directed" part of the term means. – qwerty_so Mar 21 '19 at 20:02