Chapter 29 State Machine Diagrams CS6359 Fall 2011 John Cole 1 State Machine Diagrams • They show a dynamic view, the interactions between states of an object and reaction to events. Telephone initial state off hook Idle Active state on hook transition event CS6359 Fall 2012 John Cole 2 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 3 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 4 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 5 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 6 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 7 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 8 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 9 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. transition action off hook / play dial tone Idle [valid subscriber] Active on hook guard condition CS6359 Fall 2011 John Cole 10 Nested States • States can have substates which inherit the transitions of the superstate. off hook / play dial tone Active [valid subscriber] Idle PlayingDialTone on h Talking ook digit digit connected complete Dialing CS6359 Fall 2011 John Cole Connecting 11
© Copyright 2026 Paperzz