Section 14.1. Essentials


14.1. Essentials

Let's look at the key elements of state diagrams using a simple example. Figure 14-2 shows a state diagram modeling a light. When you lift the light switch, the light turns on. When you lower the light switch, the light turns off.

Figure 14-2. The fundamental elements of a state diagram: states and transitions between states


A state diagram consists of states, drawn as rounded rectangles, and transitions, drawn as arrows connecting the states. A transition represents a change of state, or how to get from one state to the next. A state is active when entered through a transition, and it becomes inactive when exited through a transition.

The event causing the state change, or trigger, is written along the transition arrow. The light in Figure 14-2 has two states: Off and On. It changes state when the lift switch or lower switch triggers occur.

If you haven't seen state diagrams before, it may help to view the states and transitions in table form, as shown in Table 14-1. In the left column are the states, and along the top row are triggers. The table is interpreted as follows: when the object is in a state and receives a trigger, the object moves to the resulting state specified in the cell. A dash (-) means that no transition happens or that the combination is impossible. Viewing states and transitions in table form can be helpful when getting up-to-speed, but don't depend on this too heavily; details of states and transitions can be more complex, and it will become easier to work with state diagrams.

Table 14-1. Table view of light states and transitionsnot UML notation

State/Trigger

Light switch lifted

Light switch lowered

Off

On

-

On

-

Off


State diagrams usually have an initial pseudostate and a final state, marking the start and end points of the state machine, respectively. An initial pseudostate is drawn with a filled circle, and a final state is drawn with two concentric circles with a filled inner circle, as shown in Figure 14-3.

Figure 14-3. Initial pseudostate and final states in an AccountApplication state diagram


Pseudostates are special markers that direct the flow of traffic in a state diagram. As mentioned above, an initial pseudostate models the starting point of a state diagram. There are other pseudostates discussed later in "Advanced Pseudostates" that model complex transitions between states.

Now that you've seen the basic elements of state diagrams, let's look in detail at these elements.




Learning UML 2.0
Learning UML 2.0
ISBN: 0596009828
EAN: 2147483647
Year: 2007
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net