When a supervisor tells a clerk to go off-duty, the supervisor does not care whether the clerk is a shipping clerk or a stock clerk. Similarly, when an action sends a signal to an object in a class hierarchy, the sender should not need to know the subclass of the object. Rather, the signal is polymorphic. Definition: A polymorphic signal is a signal delivered at run time to a specific state machine for a class in a generalization hierarchy. In keeping with the distinction between events and signals in UML, we define also a polymorphic event. Definition: A polymorphic event is an event that has many potential receiving state machines in a generalization hierarchy
A polymorphic event is abstracted and so given a name and a signature at the superclass level. The signal is then received by the subclass state machine depending on the type at run time. Figure 13.12 illustrates the events received by the different warehouse clerk subclasses and the polymorphic event that can be received by any warehouse clerk, adding the events to the operations compartment for illustrative purposes only. Figure 13.12. Polymorphic Events in a Generalization HierarchyEach subclass's state machine may respond differently to the same signals, so that, for example, a shipping clerk may be required to complete a shipment first while a stock clerk can knock off immediately. The sender doesn't have to know the subclass of the clerk. The following action language is perfectly valid because the goOffDuty signal can be sent to any instance of a Clerk:
The following is not valid, because shipmentReady can be sent only to a shipping clerk, and one cannot determine whether the assignedClerk refers to a stock clerk or a shipping clerk:
Signals defined at a subclass level can be sent only to instances of that subclass, while polymorphic signals can be sent to any instance of the superclass. The rules for polymorphic signals mirror those for polymorphic operations in UML or an object-oriented program. We declare the event in an abstract superclass, and each subclass has to be able to interpret the signal should it arrive at run time. |