6.2.3 Numbers of links between objects
There are a number of invariants shown by the multiplicities of the associations in the class diagram. These do not need to be listed. However not all conditions on the number of links between objects are evident from the class diagram. As we have discussed, the relationship between teams and the doctors that comprise them has been modelled as a single association between and
rather than as two separate associations, one between
and
, and one between
and
. Although the multiplicity at the
end of
correctly reflects the number of doctors that can be contained in a team, it does not fully reflect the allowable number of junior doctors and consultant doctors in a team.
Activity 19
Using the first part of the answer to Activity 15 as a model, write down two invariants, one which imposes a condition on the number of objects that may be linked via
to a
object, and one which imposes a condition on the number of
objects that may be linked to a
object.
Discussion
Discusssion
-
Each
object is linked via
to exactly one
object.
-
Each
object is linked to at least one
object.
In the first invariant given in the discussion to Activity 19, notice the inclusion of ‘via ’ to identify the relevant association connecting
and
. This is because there are two associations between
and
(namely,
and
), and it is therefore necessary to be explicit about the particular association being constrained. In other words, if in stating an invariant there is more than one association between two classes involved, it is necessary to specify an association name to clarify which association is being discussed.
The statement from the requirements document which gives rise to the two invariants in Activity 19 is as follows:
Each team is headed by a consultant doctor who is the only consultant doctor in the team; the rest of the team are all junior doctors, at least one of whom must be at grade 1.
It indicates that for both the answers to Activity 19 there is a need for an even tighter condition. The single consultant doctor in the team must be the consultant doctor that heads the team, and at least one of the junior doctors in the team must be at grade 1. The second invariant can be extended to reflect this, as follows:
Each
object is linked to at least one
object for which the
attribute has a value of 1.
We will return to the first invariant in Activity 21.