lectures.alex.balgavy.eu

Lecture notes from university.
git clone git://git.alex.balgavy.eu/lectures.alex.balgavy.eu.git
Log | Files | Refs | Submodules

modeling-behavior-state-machines.html (8112B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4 <script type="text/javascript" async src="https://cdn.jsdelivr.net/gh/mathjax/MathJax@2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
      5 <link rel="Stylesheet" type="text/css" href="style.css">
      6 <title>modeling-behavior-state-machines</title>
      7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      8 </head>
      9 <body>
     10 
     11 <div id="Modeling behavior with UML State Machines"><h2 id="Modeling behavior with UML State Machines">Modeling behavior with UML State Machines</h2></div>
     12 <div id="Modeling behavior with UML State Machines-Introduction"><h3 id="Introduction">Introduction</h3></div>
     13 <p>
     14 every object has finite set of states during life.
     15 </p>
     16 
     17 <p>
     18 state machine diagram is used to:
     19 </p>
     20 <ul>
     21 <li>
     22 model possible states of system/object
     23 
     24 <li>
     25 show how state transitions occur as consequence of events
     26 
     27 <li>
     28 show behavior of system in each state
     29 
     30 </ul>
     31 
     32 <p>
     33 <img src="img/simple-example.png" alt="Simple example" />
     34 </p>
     35 
     36 <div id="Modeling behavior with UML State Machines-States"><h3 id="States">States</h3></div>
     37 <p>
     38 states are the nodes of state machine
     39 </p>
     40 
     41 <p>
     42 when a state is active:
     43 </p>
     44 <ul>
     45 <li>
     46 object is in that state
     47 
     48 <li>
     49 all internal activities in that state can be executed:
     50 
     51 <ul>
     52 <li>
     53 <code>entry/Activity</code> - when object enters the state
     54 
     55 <li>
     56 <code>do/Activity</code> - while object remains in this state
     57 
     58 <li>
     59 <code>exit/Activity</code> - when object exits the state
     60 
     61 </ul>
     62 </ul>
     63 
     64 <div id="Modeling behavior with UML State Machines-Transitions"><h3 id="Transitions">Transitions</h3></div>
     65 <p>
     66 change from one state to another
     67 </p>
     68 
     69 <p>
     70 <img src="img/transition-diagram.png" alt="Transition diagram" />
     71 </p>
     72 
     73 <p>
     74 Syntax of transitions:
     75 </p>
     76 <blockquote>
     77 <img src="img/syntax-of-transitions.png" alt="Syntax of transitions" />
     78 </blockquote>
     79     
     80 <ul>
     81 <li>
     82 Event (trigger)
     83 
     84 <ul>
     85 <li>
     86 can trigger state transition
     87 
     88 </ul>
     89 <li>
     90 Guard (condition)
     91 
     92 <ul>
     93 <li>
     94 boolean expression
     95 
     96 <li>
     97 if event occurs, guard is checked
     98 
     99 <li>
    100 if guard is true:
    101 
    102 <ol>
    103 <li>
    104 all activities in current state are terminated
    105 
    106 <li>
    107 exit activity is executed
    108 
    109 <li>
    110 transition happens
    111 
    112 </ol>
    113 </ul>
    114 <li>
    115 Activity (effect)
    116 
    117 <ul>
    118 <li>
    119 sequence of actions that happen during transition
    120 
    121 </ul>
    122 </ul>
    123 
    124 <p>
    125 Types:
    126 </p>
    127 <ul>
    128 <li>
    129 internal:
    130 
    131 </ul>
    132 <blockquote>
    133 <img src="img/internal-state-transition.png" alt="Internal state transition" />
    134 </blockquote>
    135 
    136 <ul>
    137 <li>
    138 if <code>event1</code> happens, object stays in <code>state1</code> and <code>Activity3</code> runs
    139 
    140 </ul>
    141 
    142 <ul>
    143 <li>
    144 external:
    145 
    146 </ul>
    147 <blockquote>
    148 <img src="img/external-state-transition.png" alt="External state transition" />
    149 </blockquote>
    150 
    151 <ul>
    152 <li>
    153 if <code>event1</code> happens:
    154 
    155 <ul>
    156 <li>
    157 object leaves <code>state1</code>, <code>Activity2</code> runs
    158 
    159 <li>
    160 <code>Activity3</code> runs
    161 
    162 <li>
    163 object enters <code>state1</code> and <code>Activity1</code> runs
    164 
    165 </ul>
    166 </ul>
    167 
    168 <p>
    169 Timing of transitions:
    170 </p>
    171 
    172 <p>
    173 <img src="img/table-of-transition-timing.png" alt="Table of transition timing" />
    174 </p>
    175 
    176 <div id="Modeling behavior with UML State Machines-Types of events"><h3 id="Types of events">Types of events</h3></div>
    177 <ul>
    178 <li>
    179 <span id="Modeling behavior with UML State Machines-Types of events-Signal event:"></span><strong id="Signal event:">Signal event:</strong> receipt of a signal (<code>rightmousedown</code>, <code>sendSMS(message)</code>)
    180 
    181 <li>
    182 <span id="Modeling behavior with UML State Machines-Types of events-Call event:"></span><strong id="Call event:">Call event:</strong> operation call (<code>occupy(user, lectureHall)</code>, <code>register(exam)</code>)
    183 
    184 <li>
    185 <span id="Modeling behavior with UML State Machines-Types of events-Time event:"></span><strong id="Time event:">Time event:</strong> time-based state transition (relative or absolute time)
    186 
    187 <li>
    188 <span id="Modeling behavior with UML State Machines-Types of events-Any receive event:"></span><strong id="Any receive event:">Any receive event:</strong> when any event occurs that doesn't trigger another transition from the active state
    189 
    190 <li>
    191 <span id="Modeling behavior with UML State Machines-Types of events-Completion event:"></span><strong id="Completion event:">Completion event:</strong> automatic when everything is completed in the current state
    192 
    193 <li>
    194 <span id="Modeling behavior with UML State Machines-Types of events-Change event:"></span><strong id="Change event:">Change event:</strong> permanently checking when a condition becomes true
    195 
    196 </ul>
    197 
    198 <p>
    199 A change event is permanently checked. A guard is only checked when the event occurs.
    200 </p>
    201 
    202 <div id="Modeling behavior with UML State Machines-Types of states"><h3 id="Types of states">Types of states</h3></div>
    203 <p>
    204 Initial state:
    205 </p>
    206 <ul>
    207 <li>
    208 "start" of the diagram
    209 
    210 <li>
    211 pseudo-state, system can't remain in this state
    212 
    213 <li>
    214 no incoming edges
    215 
    216 <li>
    217 outgoing edges have to be mutually exclusive and at least one target must be reachable. no events allowed.
    218 
    219 <li>
    220 system immediately switches from initial state.
    221 
    222 <li>
    223 notation: <img src="img/initial-state-notation.png" alt="Initial state notation" />
    224 
    225 </ul>
    226 
    227 <p>
    228 Final state:
    229 </p>
    230 <ul>
    231 <li>
    232 real state
    233 
    234 <li>
    235 end of sequence of states
    236 
    237 <li>
    238 can remain in this state forever
    239 
    240 <li>
    241 notation: <img src="img/final-state-notation.png" alt="Final state notation" />
    242 
    243 </ul>
    244 
    245 <p>
    246 Terminate node:
    247 </p>
    248 <ul>
    249 <li>
    250 pseudo-state
    251 
    252 <li>
    253 terminates state machine
    254 
    255 <li>
    256 modeled object is deleted
    257 
    258 <li>
    259 notation: <img src="img/terminate-node-notation.png" alt="Terminate node notation" />
    260 
    261 </ul>
    262 
    263 <p>
    264 Decision node:
    265 </p>
    266 <ul>
    267 <li>
    268 pseudo-state
    269 
    270 <li>
    271 used for alternative transitions
    272 
    273 <li>
    274 notation: <img src="img/decision-node-notation.png" alt="Decision node notation" />
    275 
    276 </ul>
    277 
    278 <p>
    279 Parallelization node:
    280 </p>
    281 <ul>
    282 <li>
    283 pseudo-state
    284 
    285 <li>
    286 splits control flow into multiple concurrent flows
    287 
    288 <li>
    289 1 incoming edge, &gt;1 outgoing edges
    290 
    291 <li>
    292 notation: <img src="img/parallelization-node-notation.png" alt="Parallelization node notation" />
    293 
    294 </ul>
    295 
    296 <p>
    297 Synchronization node:
    298 </p>
    299 <ul>
    300 <li>
    301 pseudo-state
    302 
    303 <li>
    304 merges multiple concurrent flows
    305 
    306 <li>
    307 &gt;1 incoming edge, 1 outgoing edge
    308 
    309 <li>
    310 notation: <img src="img/synchronization-node-notation.png" alt="Synchronization node notation" />
    311 
    312 </ul>
    313 
    314 <p>
    315 Composite state:
    316 </p>
    317 <ul>
    318 <li>
    319 contains substates, with only one of them active at any time
    320 
    321 <li>
    322 arbitrary nesting depth
    323 
    324 <li>
    325 higher level events take priority
    326 
    327 </ul>
    328 <blockquote>
    329 <img src="img/composite-state-diagram.png" alt="Composite state diagram" />
    330 </blockquote>
    331     
    332 <p>
    333 Orthogonal state:
    334 </p>
    335 <ul>
    336 <li>
    337 composite state divided into two or more regions, separated by dashed line
    338 
    339 <li>
    340 one state of each region is always active at some point (concurrent substates)
    341 
    342 <li>
    343 final state has to be reached in all regions to trigger completion
    344 
    345 </ul>
    346 <blockquote>
    347 <img src="img/orthogonal-state-diagram.png" alt="Orthogonal state diagram" />
    348 </blockquote>
    349 
    350 <p>
    351 Submachine state (SMS)
    352 </p>
    353 <ul>
    354 <li>
    355 to reuse parts of state machine diagrams in other ones
    356 
    357 <li>
    358 as soon as submachine state is activated, behavior of submachine is executed (subroutine)
    359 
    360 <li>
    361 notation: <code>state:submachineState</code>
    362 
    363 </ul>
    364 <blockquote>
    365 <img src="img/submachine-state-diagram.png" alt="Submachine state diagram" />
    366 </blockquote>
    367 
    368 <p>
    369 History state:
    370 </p>
    371 <ul>
    372 <li>
    373 remembers the last active substate of a composite state
    374 
    375 <li>
    376 activates 'old' substate and all entry activities run sequentially from outside to inside of composite state
    377 
    378 <li>
    379 exactly one outgoing edge of history state points to a substate. used if the composite state was never active, or it was exited via final state.
    380 
    381 <li>
    382 shallow history state restores state on the same level of the composite state (<code>H</code>)
    383 
    384 <li>
    385 deep history state restores last active substate over <em>all levels</em> (<code>H*</code>)
    386 
    387 </ul>
    388 
    389 <div id="Modeling behavior with UML State Machines-Entry and exit points"><h3 id="Entry and exit points">Entry and exit points</h3></div>
    390 <p>
    391 Encapsulation mechanism: a composite state shall be entered/exited via a state other than initial and final states.
    392 </p>
    393 
    394 <p>
    395 external transition must/need not know structure of composite state.
    396 </p>
    397 
    398 </body>
    399 </html>