6.2.4 Relationships between attribute values
We have formulated an invariant reflecting the fact that the sex of a patient must be the same as the type of ward to which they are admitted (see the discussion following Activity 14). We also know that each ward has a maximum capacity. The number of free beds must be consistent with this, leading to the following invariant:
For each
object, the value of its
attribute is less than or equal to the value of its
attribute.
Activity 20
The invariant we have just discussed constrains the relative values of two attributes of the same object. Write down a real-world constraint that requires a similar invariant involving attributes of another class in the Hospital System.
Discussion
A patient's age is the difference (in years) between the current date and their date of birth.
The invariant noted in Activity 20 could be formulated as follows:
For each
object, the value of its
attribute is equal to the difference (in years) between the current date and the value of its
attribute.