|
State Diagrams
State diagrams are used to
describe the behavior of a system. State diagrams describe all
of the possible states of an object as events occur. Each
diagram usually represents objects of a single class and track
the different states of its objects through the system.
The basic elements are rounded boxes
representing the state of the object and arrows indicting the
transition to the next state. The activity section of the
state symbol depicts what activities the object will be doing
while it is in that state.
All state diagrams being with an initial state
of the object. This is the state of the object when it is
created. After the initial state the object begins changing
states. Conditions based on the activities can determine what
the next state the object transitions to.
A State diagram consists of the following
elements.
Initial State: This shows the starting point or
first activity of the flow. Denoted by a solid circle.
State: Represents the state of object at an
instant of time. In a state diagram, there will be multiple of
such symbols, one for each state of the Object we are
discussing. Denoted by a rectangle with rounded corners and
compartments (such as a class with rounded corners to denote
an Object).
Transition: An arrow indicating the Object to
transition from one state to the other. The actual trigger
event and action causing the transition are written beside the
arrow, separated by a slash. Transitions that occur because
the state completed an activity are called "triggerless"
transitions. If an event has to occur after the completion of
some event or action, the event or action is called the guard
condition. The transition takes place after the guard
condition occurs. This guard condition/event/action is
depicted by square brackets around the description of the
event/action.
History States: A flow may require that the
object go into a trance, or wait state, and on the occurrence
of a certain event, go back to the state it was in when it
went into a wait state—its last active state. This is shown in
a State diagram with the help of a letter H enclosed within a
circle.
Event and Action: A trigger that causes a
transition to occur is called as an event or action. Every
transition need not occur due to the occurrence of an event or
action directly related to the state that transitioned from
one state to another. As described above, an event/action is
written above a transition that it causes.
Signal: When an event causes a message/trigger
to be sent to a state, that causes the transition; then, that
message sent by the event is called a signal. Represented as a
class with the <<SIGNAL >> icon above the
action/event.
Final
State: The end of the state diagram is shown by a
bull's eye symbol, also called a final state.
A final state is another example of a
pseudo state because it does not have any variable or
action described.
Below is an example of a
state diagram might look like for an Order object. When the
object enters the Checking state it performs the activity
"check items." After the activity is completed the object
transitions to the next state based on the conditions [all
items available] or [an item is not available]. If an item is
not available the order is canceled. If all items are
available then the order is dispatched. When the object
transitions to the Dispatching state the activity "initiate
delivery" is performed. After this activity is complete the
object transitions again to the Delivered state.
|