Download presentation
Presentation is loading. Please wait.
Published byLizbeth Riley Modified over 9 years ago
1
Object State Modeling for Event- Driven Systems Yonglei Tao 1
2
2 Key Takeaway Points Object state modeling concerned with the identification, modeling, design, and specification of state-dependent, reactive behavior of objects. The state pattern reduces the complexity of state behavior design and implementation, and makes it easy to change.
3
Microwave Oven Control
4
Events and Guard Conditions
5
Composite States
6
Hierarchical Statecharts
7
Guidelines A state name must reflect an identifiable situation Idle, Waiting for PIN It must be possible to exit from every state Cyclic behavior Do not confuse events and actions
8
User Interface Design 8 Interaction design Structure of the dialog between the user and the computer Visual design Screen element selection Screen layout Visual characteristics of screen elements
9
Use Case – Process Sale 9
10
State Machine Diagram 10
11
Object State Modeling - Validate PIN
12
12 Object State Modeling Steps
13
13 Collecting and Classifying State Behavior Information What to look forExampleClassificationRule Something interest happened An online application submitted. EventE1 Mode of operationA cruise control operates in activated/ deactivated modes. StateS2 Conditions that govern the processing of an event Turn on AC if room temperature is high Guard condition G1 An act associates with an event Push the lever down to set the cruising speed. ResponseR1
14
Constructing a Domain Model 14 The domain model shows relationships between the state dependent software and its context State Machine Source & Destination 1 event 1a event 1b event 2a event 2b event 3a event 3b event 3c resp. 1x resp. 1y resp. 2x resp. 2y resp. 3x Source & Destination 2 Source & Destination 3
15
A Cruise Control 15
16
16 Cruise Control Domain Model
17
17 Constructing a State Transition Table Constructing the state transition table is optional It is a systematic approach to state behavior modeling
18
18 Cruise Control State Transition Table
19
19 Use of State Transition Tables A systematic approach to ensure completeness every state-event combination is analyzed Easy to detect dead state unreachable state neglected event impossible transitions nondeterministic transitions redundant transitions inconsistent transitions Allow to generate state diagrams automatically
20
20 Converting to State Diagram
21
21 Cruising Cancelle d Converting Texts to Function Calls leverPulled(), brakeApplied() onOffButtonP ressed() Cruise Deactivated Increasin g Speed Decreasin g Speed onOffButton Pressed() Cruise Activated leverDown()/ setDesiredSpeed(), Cruising leverDown() / setDesiredSpeed() leverReleased()/ setDesiredSpeed() leverUpAnd Hold() leverDown AndHold() leverUp() leverDown AndHold()
22
22 Implementation of a Control Class An event in the state diagram implies a call to a method of the class An instance variable determines the current state of an instance of the class A method evaluates the state variable and the guard condition, executes the appropriate response actions, and updates the state variable
23
Update Design Class Diagram 23 Add methods labeling the transitions to the subject class CruiseControl onOffButtonPressed() leverDown() leverUp() brakeApplied() leverDownAndHold() leverUpAndHold() leverPulled() leverReleased() setDesiredSpeed()
24
The State Pattern Develop a program that reads a text file (such as proj1.c) and counts the number of words the number of symbol sequences in a text State-dependent behavior how to process each input character depends on its current state 24
25
State Diagram 25 symbol
26
Traditional Approach ch = getchar(); switch (state) { case ‘s’: if ( isalnum(ch) ) { state = ‘w’; wc++; } else...... case ‘w’: if ( ispuct(ch) ) {...... }...... } 26
27
Using the State Pattern 27
28
State Objects and Current State :StateS:StateW:StateP State currentState 28
29
Parsing a Text Line char[] line = new char[Maxsize]; char ch; State currentState = new StateS(); read a line of text into line for (int i=0; i<line.length(); i++) { ch = line[i]; currentState = currentState.Next (ch); } 29
30
Method Next in State S public State Next (char ch) { if ( Character.isLetterOrDigit (ch) ) { wc++; return new StateW(); } else if (Character.isSpaceChar (ch) ) return new StateS(); else { pc++; return new StateP(); } 30
31
Method Next in State W Public State Next (char ch) { if (Character.isLetterOrDigit (ch) ) return new StateW(); else if (Character.isSpaceChar (ch) ) return new StateS(); else { pc++; return new StateP(); } 31
32
Method Next in State P public State Next (char ch) { if (Character.isLetterOrDigit (ch) ) { wc++; return new StateW(); } else if (Character.isSpaceChar (ch) ) return new StateS(); else return new StateP(); 32
33
Benefits Isolate behavior that the context object shows in each state Easy to add/remove a state and to change the behavior of a state 33
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.