02291: System Integration UML State Machines Hubert Baumeister - - PowerPoint PPT Presentation

02291 system integration
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

02291: System Integration

UML State Machines Hubert Baumeister

huba@dtu.dk

DTU Compute Technical University of Denmark

Spring 2020

slide-2
SLIDE 2

UML diagrams

Wikipedia

slide-3
SLIDE 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

Safe

  • pen : bool
  • pen

close SecurePanelController doorClosed : bool candleIn : bool candleRemoved() keyTurned() closeSafe()

  • revealLock()
  • releaseKillerRabbit()
slide-4
SLIDE 4

Example

slide-5
SLIDE 5

Example Execution (Secret Panel Controller)

slide-6
SLIDE 6

Example Execution (Safe)

slide-7
SLIDE 7

Example Execution (Secret Panel Controler)

slide-8
SLIDE 8

Example Execution (Safe)

slide-9
SLIDE 9

Example Execution (Secret Panel Controler)

slide-10
SLIDE 10

States 1

slide-11
SLIDE 11

States 2

slide-12
SLIDE 12

Transitions

state state trigger [guard] / effect

UML User Manual 2nd edition

state state

  • peration [guard] / action1; action2; ...
slide-13
SLIDE 13

Example Transition

Open Lock SecretPanelController doorClosed : bool candleIn : bool ... candleRemoved() keyTurned() ...

  • releaseKillerRabbit()

... Transition of the LSM for the SecretPanelController Transition of the LSM for the Safe Safe

  • pen : boolean
  • pen()

close() Open Closed close turnKey [candleIn] / safe.open() safe 1

  • pen
slide-14
SLIDE 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)

slide-15
SLIDE 15

Life cycle state machines

Safe

  • pen : bool
  • pen

close SecurePanelController doorClosed : bool candleIn : bool candleRemoved() keyTurned() closeSafe()

  • revealLock()
  • releaseKillerRabbit()

Open Lock Wait candleRemoved[doorClosed]/this.revealLock closeSafe/safe.close() keyTurned[candleIn]/safe.open()

  • pen

closed

  • pen

close

slide-16
SLIDE 16

Life cycle state machine (LSM)

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

slide-18
SLIDE 18

Life Cycle State Machine of a counter

Counter c : int inc dec

Initial state c = 0 and all the time c ≥ 0

public Counter() { c = 0;} public void inc() { c++; } public void dec() { if (c > 0) { c--; ]}

slide-19
SLIDE 19

Nonorthogonal sub states

slide-20
SLIDE 20

Sub states II: Leaving sub states

slide-21
SLIDE 21

Orthogonal Sub states

slide-22
SLIDE 22

History states

slide-23
SLIDE 23

Activity diagrams compared with State machines

Activity diagram

slide-24
SLIDE 24

Activity diagrams compared with State Machine

Activity Diagram State Machine