Download presentation
Presentation is loading. Please wait.
Published byTyler Jennings Modified over 9 years ago
1
1 Statecharts by David Harel, 1987 State machines ⊆ statecharts A state machine consists of Named states Transitions between states Events as labels on transitions State machine by itself is meaningless Must describe what states and events mean
2
2 Statecharts by David Harel, 1987 Example: vending machine state machine Informal specification: “If user deposits two quarters and presses button for gum, a pack of gum will be dispensed.” Formal specification by state machine” Events:
3
3 Statecharts by David Harel, 1987 Example: vending machine state machine Informal specification: “If user deposits two quarters and presses button for gum, a pack of gum will be dispensed.” Formal specification by state machine” Events: “quarter” = user deposited quarter
4
4 Statecharts by David Harel, 1987 Example: vending machine state machine Informal specification: “If user deposits two quarters and presses button for gum, a pack of gum will be dispensed.” Formal specification by state machine” Events: “quarter” = user deposited quarter “gum-button” = user pressed button for gum
5
5 Statecharts by David Harel, 1987 Example: vending machine state machine Informal specification: “If user deposits two quarters and presses button for gum, a pack of gum will be dispensed.” Formal specification by state machine” Events: “quarter” = user deposited quarter “gum-button” = user pressed button for gum “done” = machine finished dispensing item States:
6
6 Statecharts by David Harel, 1987 Example: vending machine state machine Informal specification: “If user deposits two quarters and presses button for gum, a pack of gum will be dispensed.” Formal specification by state machine” Events: “quarter” = user deposited quarter “gum-button” = user pressed button for gum “done” = machine finished dispensing item States: $X indicates that user has $X credit with machine
7
7 Statecharts by David Harel, 1987 Example: vending machine state machine Informal specification: “If user deposits two quarters and presses button for gum, a pack of gum will be dispensed.” Formal specification by state machine” Events: “quarter” = user deposited quarter “gum-button” = user pressed button for gum “done” = machine finished dispensing item States: $X indicates that user has $X credit with machine “dispense-gum”: machine is dispensing gum
8
8 State Machine $0.00
9
9 State Machine $0.00$0.25 quarter
10
10 State Machine $0.00$0.25$0.5 quarter
11
11 State Machine $0.00$0.25$0.5 Disp ense- gum quarter Gum button
12
12 State Machine $0.00$0.25$0.5 Disp ense- gum quarter doneGum button
13
13 Tracing Operation of State Machine Given an initial state and a sequence of events, How does the state machine react to the sequence of events? What state does it end up in? “Event history table” : useful tool for answering this 1.Each line contains: Next event in sequence State that machine is in after event 2.First line lists the initial state
14
14 Tracing Operation of State Machine Example for the vending machine EventState -------------------------------- (start)$0.00 Quarter$0.25 Quarter$0.50 Gum-buttondispense gum Done$0.00
15
15 Deterministic/non-deterministic “… a transition to branch at a decision point. Such an FSM is known as non-deterministic.” (p269) Comment: Not very precise … NFA – a ab
16
16 Deterministic/non-deterministic “… a transition to branch at a decision point. Such an FSM is known as non-deterministic.” (p269) Comment: Not very precise … Still DFSM – Deci- sion a x y
17
17 State transition matrices Example for ATM machine – withdraw StatesEvents 1.Await cardinsert card 2.Await pinenter good pin 3.Await 2 nd pin attemptenter bad pin 4.Await amountcancel 5.dispense moneyenter amount
18
18 State transition matrices States Events
19
19 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card 2. Await pin 3. Await 2 nd pin attempt 4. Await amount 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense moneyenter amount done
20
20 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin 3. Await 2 nd pin attempt 4. Await amount 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense money enter amount done
21
21 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin4 3. Await 2 nd pin attempt 4. Await amount 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense moneyenter amount done
22
22 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin4 3. Await 2 nd pin attempt 4 4. Await amount 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense moneyenter amount done
23
23 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin43 3. Await 2 nd pin attempt 4 4. Await amount 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense money enter amount done
24
24 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin43 3. Await 2 nd pin attempt 41 4. Await amount 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense moneyenter amount done
25
25 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin431 3. Await 2 nd pin attempt 41 4. Await amount 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense money enter amount done
26
26 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin431 3. Await 2 nd pin attempt 411 4. Await amount 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense money enter amount done
27
27 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin431 3. Await 2 nd pin attempt 411 4. Await amount 1 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense money enter amount done
28
28 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin431 3. Await 2 nd pin attempt 411 4. Await amount 15 5. Dispense money StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense money enter amount done
29
29 State transition matrices CardGood pinBad pinCancelAmountDone 1. Await card2 2. Await pin431 3. Await 2 nd pin attempt 411 4. Await amount 15 5. Dispense money 1 StatesEvents Await cardinsert card Await pinenter good pin Await 2 nd pin attemptenter bad pin Await amountcancel dispense money enter amount done
30
30 State diagram = State transition matrices
31
31 Extending State Machines State machines simple and visual Disadvantages: They don’t scale up well Machine state may have to model very complex system state May end up with confusing number of transitions Sometimes want to express more complex conditions on transitions => Statecharts
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.