110 likes | 122 Views
Learn about state machine diagrams, their applications in modeling state-dependent objects, and using transitions, actions, guards, and nested states.
E N D
Chapter 29 State Machine Diagrams CS6359 Fall 2011 John Cole
State Machine Diagrams • They show a dynamic view, the interactions between states of an object and reaction to events. CS6359 Fall 2012 John Cole
Event • A significant or noteworthy occurrence • A telephone is taken off-hook • A key is pressed on a keyboard • A door is opened • A quarter is put into a vending machine CS6359 Fall 2011 John Cole
Transition • Relationship between two states that indicates that when an event occurs, the object moves from the prior state to the subsequent state. • When off-hook occurs, transition from Idle to Active state CS6359 Fall 2011 John Cole
Applying the Diagrams • If an object always responds the same way to an event, it is state-independent or modeless. • State-dependent objects react differently to messages depending upon their state. • A telephone is very state-dependent. Its response to pushing buttons depends whether it is on-hook or off-hook and whether there is an ongoing call or not. CS6359 Fall 2011 John Cole
When to Use • Consider state machines and diagrams for complex, state-dependent objects, not for state-independent objects. • Business information systems seldom have much state-dependent behavior (although the UI may have some) • Process control, device control, and telecom have many state-dependent objects CS6359 Fall 2011 John Cole
Modeling State-Dependent Objects • State machines applied in 2 ways: • Model the behavior of a complex reactive object in response to events • Model legal sequences of operations such as protocol or language specifications. A formal grammar is a kind of state machine CS6359 Fall 2011 John Cole
Complex Reactive Objects • Physical devices • Transactions between related business objects. How does sale, order or payment react to an event? • Role mutators are objects that change roles based upon events. Person changes from civilian to veteran. City changes from destination to origin. CS6359 Fall 2011 John Cole
Protocols • TCP can be understood with a state machine diagram • UI page/window flow or navigation • UI flow controllers or sessions • Use case system operations • Individual UI event handling CS6359 Fall 2011 John Cole
Transition Actions and Guards • Transition can cause an action. This may be invocation of a method. Transition may also have a test and it occurs only if the test passes. CS6359 Fall 2011 John Cole
Nested States • States can have substates which inherit the transitions of the superstate. CS6359 Fall 2011 John Cole