UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing...
-
Upload
ronald-heath -
Category
Documents
-
view
221 -
download
4
Transcript of UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing...
![Page 1: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/1.jpg)
UML
Discussion on State Machines
![Page 2: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/2.jpg)
Perfectly static system is intensely uninteresting
Because nothing ever happens
![Page 3: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/3.jpg)
Real Systems
Dynamic in nature and always something is happening internally or externally.
ATM Machine.
Robot.
Chemical Reaction.
Network Router.
![Page 4: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/4.jpg)
Objects
Objects work together to realize higher-order behaviors defined by use cases.
Object Behavior with respect to time Simple State Continuous
![Page 5: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/5.jpg)
What is State Machine
Its abstract
It has finite state of conditions of existence called states
It has set of actions performed in each state
It has set of events which causes state change to well defined rule set.
![Page 6: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/6.jpg)
State Machine Example
Possible States
RED
YELLOW
GREEN
Flashing YellowFlashing Red …
![Page 7: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/7.jpg)
What things exhibit state ?
Classes
Use cases
State Machine can be applied to object oriented systems as well as functionally decomposed ones.
![Page 8: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/8.jpg)
Use Cases State MachinesCollaborations
Common Behavior
Activity Graphs
Actions
Behavioral Elements
![Page 9: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/9.jpg)
Pseudostate
kind : PseudostateKind
SimpleState
Sy nchState
bound : UnlimitedInteger
StubState
ref erenceState : Name
FinalStateCompositeState
SubmachineState
ModelElement
(from Core)
Guard
expression : BooleanExpression
Event
StateVertex
0..*
0..1
+subv ertex
0..*
+container
0..1
StateMachine
*
1
*
+submachine
1
*
0..1
+behav ior *
+context 0..1
State
0..*
0..*
0..* +def errableEv ent
0..*
1
0..1
+top1
0..1
Procedure
(f rom Common Behav ior)0..1
0..1
0..1 +doActiv ity
0..10..1
0..1
0..1 +exit
0..10..1 0..10..1
+entry
0..1
Transition
1
0..1
1
+guard0..1
0..1
*
+trigger0..1
*1 *
+source
1
+outgoing
*
1 *
+target
1
+incoming
*
*
0..1
+transitions*
0..1
*
0..1
+internalTransition*
0..1
0..1
0..1
+ef f ect0..1
0..1
State
Transition
State Machine Guard
Event
![Page 10: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/10.jpg)
![Page 11: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/11.jpg)
State Machine
Using state machine you can Model behavior of individual object.
State Machine illustrates sequential behavior of object. Statechart Diagrams.
State to State. Activity Diagrams.
Activity to Activity.
![Page 12: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/12.jpg)
Example
Payment Authorization
Authorizing
Authorized
Delivered
Rejected
![Page 13: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/13.jpg)
Web Application Not yet logged in.
Action: Display the login page
Logged in and viewing the account balance
Display the account balance
Display logout button, and view transaction button.
Logged in and viewing recent transactions
Display recent transactions
Display logout button, and view account balance button.
Logged out
Display “Goodbye page”
![Page 14: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/14.jpg)
![Page 15: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/15.jpg)
Validate Login/PIN
![Page 16: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/16.jpg)
Word Processing
![Page 17: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/17.jpg)
Brew Controller of coffee machine
![Page 18: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/18.jpg)
Coffee Machine Tank
![Page 19: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/19.jpg)
Sequential Sub states
![Page 20: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/20.jpg)
Concurrent Substates
![Page 21: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/21.jpg)
Food For Thought….
Identify States
![Page 22: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/22.jpg)
Hypothetical State Machine
Event Queue When event is received it is placed in
queue of target
Event Dispatcher When delivered to state machine
Event Processor Consumed and event is complete
![Page 23: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/23.jpg)
State Machine Concepts
Context An association to the model element
that whose behavior is specified by this state machine
States
Transitions
Event
![Page 24: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/24.jpg)
State Machine Concepts
Context
States models a situation during which
some (usually implicit) invariant condition holds.
Transitions
Event
![Page 25: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/25.jpg)
State
Simple State No SubstatesInitial State Object comes into beingFinal State The entire state machine has completed A final state cannot have any outgoing
transitions
![Page 26: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/26.jpg)
State Machine Concepts
Context
States
Transitions A transition is a directed relationship
between a source state and target state
Event
![Page 27: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/27.jpg)
Transition
Guard
TriggerSource
Target
Effects
![Page 28: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/28.jpg)
Guard
A guard is a Boolean expression that is attached to a transition as a fine-grained control over its firing. If the guard is true at that time, the
transition is enabled, otherwise, it is disabled.
![Page 29: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/29.jpg)
State Machine Concepts
Context
States
Transitions
Event An event is a specification of a type
of observable occurrence
![Page 30: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/30.jpg)
TimeEvent
when : TimeExpression
ChangeEvent
changeExpression : BooleanExpression
Operation(from Core)
CallEvent
1
*
+operation 1
+occurrence *
SignalEvent
Signal(from Common Behavior)
*
1
+occurrence *
+signal 1
Parameter(from Core)
Event
* 0..1
+parameter
*
{order...
0..1
ModelElement(from Core)
![Page 31: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/31.jpg)
Events
Call Event Reception of request to synchronously
invoke operation. Creation of object
Deletion of object
Time Event Models expiration of specific deadline.
![Page 32: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/32.jpg)
Events…
Signal Event Reception of asynchronous signal
![Page 33: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/33.jpg)
![Page 34: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/34.jpg)
Events…
Change Event Implicit Results as a change in some value of
object attribute
![Page 35: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/35.jpg)
Practical Implementations
Mapping of Statechart to efficient code
Common Approaches Double Nested Switch Statements Action state tables Generic state machine interpreters State Patterns in OO Paradigm
![Page 36: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/36.jpg)
![Page 37: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/37.jpg)
/* States. */ #define IDLE 0 #define DIAL 1 #define ALERTING 2 #define CONNECTED 3 #define BUSY 4 #define RINGING 5
/* Possible inputs */ #define ON_HOOK_IND 0 #define OFF_HOOK_IND 1 #define DIGITS_IND 2 #define CONNECTED_IND 3 #define INCOMING_CALL_IND 4 #define TIMEOUT_IND 5 #define PICKUP_IND 6
![Page 38: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/38.jpg)
int transtab[][] = /* transtab[Input][CurrentState] => NextState */ { /* IDLE DIAL ALERTING CONNECTED BUSY RINGING */
{ IDLE, IDLE, BUSY, IDLE, IDLE, IDLE }, /* ON_HOOK_IND */ { DIAL, DIAL, BUSY, IDLE, IDLE, IDLE }, /* OFF_HOOK_IND */ { IDLE, ALERTING, IDLE, IDLE, IDLE, IDLE }, /* DIGITS_IND */ { IDLE, DIAL, ALERTING, IDLE, IDLE, IDLE }, /* CONNECTED_IND */ { RINGING, DIAL, IDLE, CONNECTED, BUSY, RINGING }, /* INCOMING_CALL_IND */ { IDLE, DIAL, BUSY, IDLE, IDLE, IDLE }, /* TIMEOUT_IND */ { IDLE, DIAL, BUSY, IDLE, IDLE, CONNECTED }, /* PICKUP_IND */ };
curstate = transtab[event][curstate];
int curstate = IDLE;
![Page 39: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/39.jpg)
Who defines state transitions ?
May Define StateMachine
![Page 40: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/40.jpg)
Who defines statemachine..
Context
States Themselves
State Tables
![Page 41: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/41.jpg)
Guidelines
Create A State Chart When Behavior Differs Based on State
Place The Initial State In The Top-Left Corner
Place The Final State In The Bottom-Right Corner
State Names Should be Simple but Descriptive
Question “Black Hole” States
Question “Miracle” States
Create a Hierarchy of State Charts for Very Complex Entities
Name Transition Events in Past Tense
![Page 42: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/42.jpg)
What Next
Identify the implementation schemes
Use XMI
Aim for changes in statemachine which will need no or minimal changes to existing state implementations
![Page 44: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/44.jpg)
![Page 45: UML Discussion on State Machines Perfectly static system is intensely uninteresting Because nothing ever happens.](https://reader036.fdocuments.us/reader036/viewer/2022062515/56649f445503460f94c650cd/html5/thumbnails/45.jpg)