02291: System Integration UML State Machines Hubert Baumeister - PowerPoint PPT Presentation
02291: System Integration UML State Machines Hubert Baumeister huba@dtu.dk DTU Compute Technical University of Denmark Spring 2020 UML diagrams Wikipedia Example Task: Implement a control panel for a safe in a dungeon The safe
02291: System Integration UML State Machines Hubert Baumeister huba@dtu.dk DTU Compute Technical University of Denmark Spring 2020
UML diagrams Wikipedia
Example ◮ Task: Implement a control panel for a safe in a dungeon ◮ The safe should be visible only when a candle has been removed ◮ The safe door opens only when the key is turned after the candle has been replaced again ◮ If the key is turned without replacing the candle, a killer rabbit is released SecurePanelController Safe doorClosed : bool open : bool candleIn : bool open candleRemoved() close keyTurned() closeSafe() -revealLock() -releaseKillerRabbit()
Example
Example Execution (Secret Panel Controller)
Example Execution (Safe)
Example Execution (Secret Panel Controler)
Example Execution (Safe)
Example Execution (Secret Panel Controler)
States 1
States 2
Transitions trigger [guard] / effect state state UML User Manual 2nd edition operation [guard] / action1; action2; ... state state
Example Transition Transition of the LSM for the SecretPanelController turnKey [candleIn] / safe.open() Lock Open SecretPanelController doorClosed : bool candleIn : bool ... candleRemoved() keyTurned() ... - releaseKillerRabbit() ... Transition of the LSM for the Safe safe 1 Safe open : boolean open() close() open Closed Open close
How to use State Machines ◮ In general: ◮ Focus on states and how a system reacts to events ◮ e.g. modal user interfaces ◮ e.g. hardware controller ◮ Model the life of an object → Life cycle state machine (LSM) → From the creation of the object to its destruction → Methods are events ◮ Model the allowed interaction between components ◮ Communication protocols → Protocol state machines (PSM)
Life cycle state machines SecurePanelController Safe doorClosed : bool open : bool candleIn : bool open candleRemoved() close keyTurned() closeSafe() -revealLock() -releaseKillerRabbit() closeSafe/safe.close() Open keyTurned[candleIn]/safe.open() open closed open close candleRemoved[doorClosed]/this.revealLock Wait Lock
Life cycle state machine (LSM)
Life cycle state machine: Possible implementation public class SecretPanelController { enum states { wait, lock, open, finalState }; states state = states.wait; public void candleRemoved() { switch (state) { case wait: if (doorClosed()) { state = states.lock; break; } } } public void keyTurned() { switch (state) { case lock: if (candleIn()) { state = states.open; safe.open(); } else { state = states.finalState; releaseRabbit(); } break; } } ... }
Life Cycle State Machine of a counter Initial state c = 0 and all the time c ≥ 0 Counter c : int public Counter() { c = 0;} inc public void inc() { c++; } dec public void dec() { if (c > 0) { c--; ]}
Nonorthogonal sub states
Sub states II: Leaving sub states
Orthogonal Sub states
History states
Activity diagrams compared with State machines Activity diagram
Activity diagrams compared with State Machine Activity Diagram State Machine
Recommend
More recommend
Explore More Topics
Stay informed with curated content and fresh updates.