Upload
dominick-west
View
228
Download
0
Embed Size (px)
DESCRIPTION
基礎 State Diagrams 東吳大學資訊科學系 江清水 Tracking Entry / setMode(ontrack) Exit / setMode(offtrack) Newtarget / tracker.Acquire() Do / followTarget selfTest / defer Name Entry action Exit action Internal transition Activity Deferred event Advanced states and transition Example entry/type “login” exit/login (user name,password) do/get user name do/get password help/display help Login
Citation preview
基礎 State Diagrams 東吳大學資訊科學系 江清水
Key Terms
Basic action activity composition state event state
action state activity state initial state final state
Advance event trigger message triggerless transition
Basic state diagram substate
Sequential substate History substate Concurrent substate
transition
基礎 State Diagrams 東吳大學資訊科學系 江清水
State Diagram: 描述單一物件其狀態的轉換及順序。•State( 狀態 ): 在 Object 執行過某動作 (Action) 或某事件 (Event)發生後, Object 被改變的狀態,其包含 2 個部份。
Name Compartment :State 的名稱。Internal Transition Compartment: 在 State 內部一連串的 動作, 其語法如 下: event-name argument-list’[‘guard-condition’]’’/’action-express
共有 3 種內定的事件‘entry’’/’action-express: 當進入 State 時,所執行動作‘exit’’/’action-express: 當離開 State 時,所執行的動作‘do’’/’action-express: 執行動作除以上 3 種外,也可以使用者自定
State
Name Compartment
Internal Transition Compartment
entry/actionexit/actiondo/action自訂 /action
Name
Notation and Semantics
基礎 State Diagrams 東吳大學資訊科學系 江清水
Tracking
Entry / setMode(ontrack)
Exit / setMode(offtrack)
Newtarget / tracker.Acquire()
Do / followTarget
selfTest / defer
Name
Entry action
Exit action
Internal transition
Activity
Deferred event
Advanced states and transition
Example
entry/type “login”exit/login (user name,password)do/get user namedo/get passwordhelp/display help
Login
基礎 State Diagrams 東吳大學資訊科學系 江清水
•Start ( 開始 ):State Diagram 中所有狀態的開始。•End ( 結束 ): State Diagram 的所有狀態的結束。
Start
End
states
Idle Running
finished
keypressshutdown
Notation and Semantics
Example
基礎 State Diagrams 東吳大學資訊科學系 江清水
Transition ( 轉變 ): 由箭頭與 Transition String 組成, Transition
String 由物件狀態轉移時的限制 (Guard Condition) 、發生的事件 (Event) 或執行的動作 (Action) 所組成 ,其 語法如下:event-signature ‘[‘guard-condition’]’ ‘/’ action-expres
s ‘^’ send-clause 。
State transition
Transition String
State transition
E1 (p:C) [cond] / action1;action2Source state target state
Notation and Semantics
基礎 State Diagrams 東吳大學資訊科學系 江清水
Idle Searching Engaging
Tracking Engaging
noise
contact
After (2seconds)/ send c.isAlive
Action
Event trigger with parameters
guard condition
Transition example
Example
TargetAt(p) [isTheat] /
t.addTarget(p)
Time event
send signal
self-transition
event trigger
trigerless transition
基礎 State Diagrams 東吳大學資訊科學系 江清水
Composite State ( 合成狀態 ): 整個 State 稱為 Superstate , State A 、 B 、 C 、 D 稱為 Substate , State A與 State B 的關係為 or 的關係, State C 與 State D ,關係也是 or ,而用虛線隔開 的上下兩者關係為 and 。
Notation and Semantics
Idle Searching
Idle SearchingkeyPress
maintenance
Testing
Commanding [continue]
[not continue]
Idle
Concurrent substates
State A State B
State C State D
Superstate
maintain
Examples
基礎 State Diagrams 東吳大學資訊科學系 江清水
Example
Validating
processing
Active
Ready / turnON()Idle
Maintenance
selecting
printing
cardinserted
cancel[continue]
[not continue]
Entry / readCard
Exit / ejectcard
Sequential substates
maintain
基礎 State Diagrams 東吳大學資訊科學系 江清水
History indicator: 記錄 Superstate 內部的狀態,當再回到 Superstate 時,能回到離開時的狀態。Superstate
H
selecting
copying
command
Cleaning up
H
Backing Up
query
History State
Examples:
Notation and Semantics
基礎 State Diagrams 東吳大學資訊科學系 江清水
Synchronation bar: 表示用來強調 (Complex Transition) ,可以有多個輸入進入一個 superstate 、最後結束後一起輸出
Setup CleanupA1
B1
A2
B1
Notation and Semantics
Examples:
Setup CleanupA1
B1
A2
B1
基礎 State Diagrams 東吳大學資訊科學系 江清水
ONOFFOn()
Off()
Remote Control
On/PlayOn/StopOFF
CD PlayerOn() Play()
Stop()Off()
Off./Stop()
Play() Stop()
On() Off() Play() Stop()
Transition, message
Review examples
基礎 State Diagrams 東吳大學資訊科學系 江清水
OS running Restart OSRestart()
Start Install shield
Install software
entry/Ask install questiondo/Install software
Install^Self.Restart()
H
entry/Fix diskdo/Show question dialogdo/Ask alternative
Disk errorentry/Show question dialogdo/Ask alternative
Memory low
Disk Error()Out of memory()
[Alternative=continue][alternative=try again]
[alternative=stop]
[Alternative=stop]
Start,End,Transition,Component,History
Create()
Review examples
基礎 State Diagrams 東吳大學資訊科學系 江清水States
Idle
Cooling Activating
active
Toohot(desired Temp)
atTempatTemp
TooCold(desired Temp)
Heating
Ready / turnON()
Toohot(desired Temp)
TooCold(desired Temp)
Review examples
基礎 State Diagrams 東吳大學資訊科學系 江清水
waiting
Put(c) [c /=‘<’]
/ return false
GettingToken
Put(c) [c /=‘>’]
/token.append(c);return false
GettingBody
Put(c) [c /=‘;’]
/token.append(c); return false
Put(c) [c==‘<’]
Put(c) [c==‘>’]
Put(c) [c==‘;’]
/ return true
Modeling Reactive Objects
Message : ‘<’ string ‘>’ string ‘;’
Review examples
基礎 State Diagrams 東吳大學資訊科學系 江清水
processing
Receiving
Idle
Transmitting
selecting
printing
ringing
Error/ print report
headerOK
Entry / pickUp
Exit / disconnect
State Diagram
checkSumOKhangUp
sendFax
Review examples