02291 system integration
play

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


  1. 02291: System Integration UML State Machines Hubert Baumeister huba@dtu.dk DTU Compute Technical University of Denmark Spring 2020

  2. UML diagrams Wikipedia

  3. 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()

  4. Example

  5. Example Execution (Secret Panel Controller)

  6. Example Execution (Safe)

  7. Example Execution (Secret Panel Controler)

  8. Example Execution (Safe)

  9. Example Execution (Secret Panel Controler)

  10. States 1

  11. States 2

  12. Transitions trigger [guard] / effect state state UML User Manual 2nd edition operation [guard] / action1; action2; ... state state

  13. 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

  14. 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)

  15. 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

  16. Life cycle state machine (LSM)

  17. 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; } } ... }

  18. 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--; ]}

  19. Nonorthogonal sub states

  20. Sub states II: Leaving sub states

  21. Orthogonal Sub states

  22. History states

  23. Activity diagrams compared with State machines Activity diagram

  24. Activity diagrams compared with State Machine Activity Diagram State Machine

Recommend


More recommend