5.2 Summary of criteria
We will end this section by summarising the criteria to be considered when deciding whether an event is best represented by a class or an association.
Does the event have any properties whose values need to be recorded? For example, in the Hospital System, had there been a need to record the date of a patient's treatment or the medication that a treatment involved, we would have modelled treatment by a class associated with and .
Does the event involve more than two other significant entities? For example, were nurses part of our system domain, a treatment might sometimes involve a nurse as well as the patient and the doctor. In that case too, a class would be necessary, since three objects would need to be linked rather than just two.
Do different occurrences of the event involving the same entities need to be recorded? For example, if there were a need to record each treatment of a given patient by a particular doctor, a class would be appropriate, because an association only allows for one link between the same two objects.
Where none of these situations pertains – when an event involves instances of only two classes, has no significant properties of its own, and where it is not necessary to record multiple occurrences involving the same two entities – the event should normally be modelled as an association between the two classes.
Consider the following excerpt from a requirements document for an Election Campaign System. Identify all the events in the description that should be represented in the conceptual model, decide which of them should be modelled by a class and which by an association, and give reasons for your decisions. Sketch a class diagram, excluding multiplicities.
A system is required to model the organisation of an election campaign by a constituency political party. During the campaign, local activists carry out telephone canvassing and visit local community organisations from which the party hopes to gain support. The party records all the telephone calls and visits that have taken place. In the case of telephone calls the date of the call is recorded, together with a note of any issues mentioned by the constituent as likely to influence their voting behaviour. The party also organises a number of public meetings in different parts of the constituency. Each of these meetings is chaired by a member of the local committee, and involves at least two speakers, a local activist and a guest speaker selected from a panel drawn up by the national headquarters of the party.
You may assume that the following classes have already been identified as necessary: , , , and .
The description mentions three relevant types of event – visits to local organisations, public meetings and telephone conversations.
The visits involve only two classes – and . There is no indication that specific information needs to be recorded about visits or that their number is significant, so it is appropriate to model them by a association between and .
Public meetings, on the other hand, involve instances of three other classes: , and . It is therefore appropriate to model this event as a class.
Telephone conversations between party activists and constituents involve only two classes, but we are told that certain details of the conversation – the date on which it took place and the issues raised by the constituent – are recorded. To model this, a class is needed, which will have two attributes, and .
A class diagram for the system (excluding multiplicities) is given in Figure 24.