Section 14.5. Advanced State Behavior


14.5. Advanced State Behavior

You've seen the most common ways to model states. This section shows how to model additional details of a state, including entry behavior, exit behavior, and reactions to events while in a state.

Figure 14-14 shows the detailed notation for a state: a large rounded rectangle with separate compartments for internal behavior and internal transitions.

14.5.1. Internal Behavior

Internal behavior is any behavior that happens while the object is in a state. You've already seen do behavior, which is behavior that is ongoing while the state is active. Internal behavior is a more general concept that also includes entry and exit behavior.

Figure 14-14. Internal behavior and transitions of the Attack state


Internal behavior is written as label / behavior. The label indicates when the behavior executesin other words, events or circumstances causing the behavior. There are three special labels: entry, exit, and do.

Entry behavior happens as soon as the state becomes active and is written as entry/behavior. Exit behavior happens immediately before the state becomes inactive and is written as exit/behavior.

In Figure 14-15, unsheath sword is entry behavior and sheath sword is exit behavior. Unlike do behavior, entry and exit behaviors can't be interrupted.

Figure 14-15. The middle compartment shows internal behavior


14.5.2. Internal Transitions

An internal transition is a transition that causes a reaction within a state, but doesn't cause the object to change states. An internal transition is different from a self transition (see Figure 14-11) because self transitions cause entry and exit behavior to occur whereas internal transitions don't.

Internal transitions are written as trigger [guard] / behavior, and they are listed inside a state. In Figure 14-16, the Attack has an internal transition: when an opponent swings his weapon and is less than three feet away, the troll dodges.

Figure 14-16. The bottom compartment shows internal transitions


Use internal transitions to model reactions to events that don't cause state changes. For example, you could use internal transitions to show that a pause-and-serve coffee-maker suspends dispensing the coffee when you remove the coffee pot but doesn't leave the Brewing state, as shown in Figure 14-17.

Figure 14-17. An internal transition models a reaction while staying in the same state





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