|I l @ ve RuBoard|
A state is a condition during the life of an object during which it satisfies some condition, performs some action, or waits for an event. The state of an object may be characterized by the value of one or more of the attributes of the class. For example, a CourseOffering object may be open (able to add a student) or closed (maximum number of students already assigned to the CourseOffering object). The state depends upon the number of students assigned to the particular CourseOffering object. Additionally, a state of an object may be characterized by the existence of a link to another object. A professor may be teaching or on sabbatical. This depends upon the existence of a link to a CourseOffering object. Looking at the state of an object can validate the multiplicity chosen for a relationship to another object. That is, if being in a state depends upon the existence of a link to another object, this implies that the multiplicity of the relationship modifying the role of the associated class must include zero (i.e., the relationship is optional). Thus, the states of an object are found by examining the attributes and links defined for the object.
The UML notation for a state is a rectangle with rounded corners as shown in Figure 9-2.
Figure 9-2. UML Notation for a State
A statechart diagram encompasses all the messages that an object can send and receive. Scenarios represent one path through a statechart diagram. The interval between two messages sent by an object typically represents a state. Therefore, sequence diagrams may be examined to discover the states for an object (look at the space between the lines representing messages received by the object). If we had created sequence diagrams for each use case in the ESU Course Registration system, we would discover that objects in CourseOffering class can be in one of the following states: Initialization (created prior to registration but students have not been added to it), Open (able to accept students), Closed (maximum number of students already registered for it), Canceled (no longer offered ).
CREATING STATES IN RATIONAL ROSE
The states of the CourseOffering class are shown in Figure 9-3.
Figure 9-3. States
|I l @ ve RuBoard|