Page 149 -
P. 149

132   Chapter 5   System modeling



                                                                         Doctor



                                                            Hospital                General
                                                             Doctor                Practitioner



                                               Consultant              Team Doctor




                                                             Trainee                 Qualified
                  Figure 5.11 A generalization               Doctor                  Doctor
                  hierarchy




                                    these classes. This allows us to infer that different members of these classes have some
                                    common characteristics (e.g., squirrels and rats are rodents). We can make general state-
                                    ments that apply to all class members (e.g., all rodents have teeth for gnawing).
                                       In modeling systems, it is often useful to examine the classes in a system to see
                                    if there is scope for generalization. This means that common information will be
                                    maintained in one place only. This is good design practice as it means that, if
                                    changes are proposed, then you do not have to look at all classes in the system to
                                    see if they are affected by the change. In object-oriented languages, such as Java,
                                    generalization is implemented using the class inheritance mechanisms built into the
                                    language.
                                       The UML has a specific type of association to denote generalization, as illus-
                                    trated in Figure 5.11. The generalization is shown as an arrowhead pointing up to
                                    the more general class. This shows that general practitioners and hospital doctors
                                    can be generalized as doctors and that there are three types of Hospital Doctor—
                                    those that have just graduated from medical school and have to be supervised
                                    (Trainee Doctor); those that can work unsupervised as part of a consultant’s team
                                    (Registered Doctor); and consultants, who are senior doctors with full decision-
                                    making responsibilities.
                                       In a generalization, the attributes and operations associated with higher-level
                                    classes are also associated with the lower-level classes. In essence, the lower-level
                                    classes are subclasses inherit the attributes and operations from their superclasses.
                                    These lower-level classes then add more specific attributes and operations. For
                                    example, all doctors have a name and phone number; all hospital doctors have a staff
                                    number and a department but general practitioners don’t have these attributes as they
                                    work independently. They do however, have a practice name and address. This is
                                    illustrated in Figure 5.12, which shows part of the generalization hierarchy that I
                                    have extended with class attributes. The operations associated with the class Doctor
                                    are intended to register and de-register that doctor with the MHC-PMS.
   144   145   146   147   148   149   150   151   152   153   154