170 likes | 198 Views
State Behavior. Patrick Bailey Keith Vander Linden Calvin College. State Behavior. Objects can display: Reactive, state-independent behavior Discrete, state-dependent behavior Continuous behavior UML models this intra-object behavior using State Machine diagrams. State Machine Diagrams.
E N D
State Behavior Patrick Bailey Keith Vander Linden Calvin College
State Behavior • Objects can display: • Reactive, state-independent behavior • Discrete, state-dependent behavior • Continuous behavior • UML models this intra-object behavior using State Machine diagrams.
State Machine Diagrams • State diagrams can be specified for classes, use cases, or other systems. • They specify object behavior over a number of use cases. • Key elements: • States • Transitions
Example: State Machine Diagram Example from www.ilogix.com, August, 2005
Outline • History • State Diagrams • Implementing State Transitions • Using State Diagrams
David HarelState Charts • Developed statecharts, a higraph-based amalgam of graphs and Venn diagrams. • Statecharts are the basis of UML state machine diagrams. Harel’s original digital watch state chart Image from www.wisdom.weizmann.ac.il, August, 2005
States • Use states to represent conditions of objects in time. • Internal Activities: • On Entry • On Exit • Internal Transition • Do Activities
Transitions • Transitions indicate movement from one state to another. • Syntax: event-name ( parameter-list ) [ guard-expression ] / action-list
Transition Events • Events that can trigger transitions include: • Signal events • Call events • Time events • Change events • Transitions without events and guards are followed immediately.
Super-States • Use super-states to represent sets of states that share common transitions and activities.
Action Execution Order • Actions are executed in this basic order: • Exit actions • Transition actions • Entry actions • In the context of super/sub-states, outer actions are executed before inner actions.
And States & Or States • We’ve already seen Or states. • And states represent orthogonal state spaces. Example from Fowler, M., UML Distilled, 2004.
Pseudo-States Pseudo-states are state-like constructions that represent a variety of things, including: • Conditions • History • Termination • Branching varieties
Implementing State Diagrams • Code generators can implement state behavior in several ways: • Nested switch statements • State pattern • State table
Using State Diagrams • State diagrams represent intra-object behavior. • Combine them with other diagrams to represent inter-object behavior. • Use them only for objects with “interesting” state-based behavior. • Take care to avoid: • Ambiguous specifications • Race conditions