Section 14.3. Transitions


14.3. Transitions

A transition, shown with an arrow, represents a change of states from a source state to a target state . A transition description, written along the arrow, describes the circumstances causing the state change to occur.

The previous state diagrams in this chapter had fairly simple transition descriptions because they consisted only of triggers. For example, the light in Figure 14-2 changed state in response to the triggers lift switch and lower switch. But transition descriptions can be more complex. The full notation for transition descriptions is trigger[guard] / behavior, where each element is optional, as shown in Figure 14-6. This section defines each of these elements, and then in "Transition Variations" we'll show how these elements interact to model different types of state changes.

Figure 14-6. This input processing state diagram models features a trigger, guard, and transition behavior along one of its transitions


A trigger is an event that may cause a transition. In a system that processes user input, a keystroke trigger may cause the system to change states from Gathering input to Processing input.

In addition to triggers , transitions can also be prompted by the completion of internal behavior, as discussed later in this chapter.


A guard is a Boolean condition that permits or blocks the transition. When a guard is present, the transition is taken if the guard evaluates to true, but the transition is blocked if the guard is false. Continuing the user input example, after a keystroke trigger occurs, a guard can be used to block a transition if the input is less than the required length. Guards are commonly used to model a transition being blocked or a choice between transitions, as discussed next in "Transition Variations."

Transition behavior is an uninterruptible activity that executes while the transition takes place (if the transition is taken). For example, transition behavior could include submitting the user's input for processing while changing states from Gathering input to Processing input.

Figure 14-6 shows all three elements of a transitiontrigger, guard, and transition behavior. When a keystroke occurs and the input is the required length, the transition from Gathering input to Processing input is taken. While the transition occurs, the transition behavior submit input is invoked. Figure 14-6 also shows that a state can transition to itself; this is known as a self-transition .

14.3.1. Transition Variations

Figure 14-7 shows a state diagram for a CD player. Its transition descriptions feature an assortment of triggers, guards, and transition behavior. Let's break this diagram apart to see how combinations of guards and triggers can be used to model different types of state changes.

Figure 14-7. CD player state diagram, featuring a variety of transition descriptions


If a trigger is specified but no guard is, then the transition is taken when the trigger occurs. This is useful for modeling a state change in response to an event. In Figure 14-8, the CD player moves from the Playing state to Stopped when press stop occurs.

Figure 14-8. The most common type of transition features only a trigger


If a trigger and a guard are specified, then the transition is taken when the trigger occurs if the guard evaluates to true. Otherwise, the transition isn't taken. Combining a trigger and a guard is useful for modeling that a transition can be blocked depending on a condition. You can also use guards to model a choice between transitions, as you'll see later.

In Figure 14-9, the CD player moves from the Stopped state to Playing when press play occurs, but only if a disc is in the tray.

Figure 14-9. A guard will block a transition if it evaluates to false


If neither a trigger nor a guard are specified, then the transition is taken immediately after the source state's internal behavior (if any) is complete. This is useful for modeling a transition caused by completion of internal behavior. Figure 14-10 shows a triggerless, guardless transition leading from Playing to Stopped, which means that the CD player moves to the Stopped state as soon as it finishes reading the disc. (This transition is not seen in the full CD player state diagram in Figure 14-7, but is included to explain triggerless transitions, shown in Figure 14-11.)

Figure 14-10. In this example, a transition is caused by the completion of internal behavior


Figure 14-11. Using guards to model a choice between paths


Figure 14-9 showed the use of guards to block a transition. You can also use guards to show a choice between transitions: the transition whose guard evaluates to true is taken. In Figure 14-11, after the CD player is done reading the disc, it will either move to the Stopped state if there are no more discs or transition back to the Playing state if there are more discs. Notice that if there are more discs, the transition includes transition behaviorchanging the disc.

As a presentation option for choices, you can use a choice pseudostate, discussed later in "Advanced Pseudostates."




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