Common Modeling Techniques
Modeling a Family of Signals
In most event-driven systems, signal events are hierarchical. For example, an autonomous robot might distinguish between external signals, such as a Collision, and internal ones, such as a HardwareFault. External and internal signals need not be disjoint, however. Even within these two broad classifications, you might find specializations. For example, HardwareFault signals might be further specialized as BatteryFault and MovementFault. Even these might be further specialized, such as MotorStall, a kind of MovementFault.
Generalization is discussed in Chapters 5 and 10 . |
State machines are discussed in Chapter 22 . |
- Consider all the different kinds of signals to which a given set of active objects may respond.
- Look for the common kinds of signals and place them in a generalization/specialization hierarchy using inheritance. Elevate more general ones and lower more specialized ones.
- Look for the opportunity for polymorphism in the state machines of these active objects. Where you find polymorphism, adjust the hierarchy as necessary by introducing intermediate abstract signals.
Abstract classes are discussed in Chapters 5 and 9 . |
Figure 21-6. Modeling Families of Signals

Modeling Abnormal Occurrences
An important part of visualizing, specifying, and documenting the behavior of a class or an interface is specifying the abnormal occurrences that its operations can produce. If you are handed a class or an interface, the operations you can invoke will be clear, but the abnormal occurrences that each operation may raise will not be clear unless you model them explicitly.
Classes are discussed in Chapters 4 and 9; interfaces are discussed in Chapter 11; stereotypes are discussed in Chapter 6 . |
- For each class and interface, and for each operation of such elements, consider the normal things that happen. Then think of things that can go wrong and model them as signals among objects.
- Arrange the signals in a hierarchy. Elevate general ones, lower specialized ones, and introduce intermediate exceptions as necessary.
- For each operation, specify the abnormal occurrence signals that it may raise. You can do so explicitly (by showing send dependencies from an operation to its signals) or you can use sequence diagrams illustrating various scenarios.
Figure 21-7 models a hierarchy of abnormal occurrences that may be produced by a standard library of container classes, such as the template class Set. This hierarchy is headed by the abstract signal Error and includes three specialized kinds of errors: Duplicate, Overflow, and Underflow. As shown, the add operation may produce Duplicate and Overflow signals, and the remove operation produces only the Underflow signal. Alternatively, you could have put these dependencies in the background by naming them in each operation's specification. Either way, by knowing which signals each operation may send, you can create clients that use the Set class correctly.
Figure 21-7. Modeling Error Conditions

Template classes are discussed in Chapter 9 . |