lectures.alex.balgavy.eu

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

sequence-diagrams.html (9667B)


      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>sequence-diagrams</title>
      7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      8 </head>
      9 <body>
     10 
     11 <div id="Sequence Diagrams"><h2 id="Sequence Diagrams">Sequence Diagrams</h2></div>
     12 <div id="Sequence Diagrams-Introduction"><h3 id="Introduction">Introduction</h3></div>
     13 <p>
     14 it's a way to model interactions between objects
     15 </p>
     16 
     17 <p>
     18 interaction specifies how messages and data are exchanged between objects
     19 </p>
     20 
     21 <p>
     22 interaction partners: human (lecturer, admin) or non-human (server, printer, software)
     23 </p>
     24 
     25 <p>
     26 interactions: conversation between people, message exchange between human and software, communication protocols, sequence of method calls in program, etc.
     27 </p>
     28 
     29 <div id="Sequence Diagrams-Basics"><h3 id="Basics">Basics</h3></div>
     30 <div id="Sequence Diagrams-Basics-Interactions, interaction partners"><h4 id="Interactions, interaction partners">Interactions, interaction partners</h4></div>
     31 <p>
     32 a sequence diagram is 2D:
     33 </p>
     34 <ul>
     35 <li>
     36 horizontal axis: involved interaction partners
     37 
     38 <li>
     39 vertical axis: chronological order of interaction
     40 
     41 </ul>
     42 
     43 <p>
     44 interaction: sequence of event specifications
     45 </p>
     46 
     47 <p>
     48 <img src="img/sequence-diagram-example.png" alt="Sequence diagram example" />
     49 </p>
     50 
     51 <p>
     52 interaction partners are lifelines:
     53 </p>
     54 <ul>
     55 <li>
     56 head of lifeline is rectangle containing <code>object:Class</code>
     57 
     58 <li>
     59 body of lifeline is vertical dashed line representing lifetime of associated object
     60 
     61 </ul>
     62 
     63 <div id="Sequence Diagrams-Basics-Messages"><h4 id="Messages">Messages</h4></div>
     64 <p>
     65 message is defined via send and receive events
     66 </p>
     67 
     68 <p>
     69 execution specification (optional):
     70 </p>
     71 <ul>
     72 <li>
     73 continuous bar
     74 
     75 <li>
     76 used to visualize when interaction partner executes a behavior
     77 
     78 </ul>
     79 
     80 <p>
     81 <img src="img/exchanging-messages-example-on-diagram.png" alt="Exchanging messages example on diagram" />
     82 </p>
     83 
     84 <p>
     85 rules:
     86 </p>
     87 
     88 <p>
     89 <img src="img/exchanging-messages-rules.png" alt="Exchanging messages rules" />
     90 </p>
     91 
     92 <p>
     93 synchronous message:
     94 </p>
     95 <ul>
     96 <li>
     97 sender waits until it has received response message before continuing
     98 
     99 <li>
    100 syntax: <code>msg(par₁, par₂)</code>
    101 
    102 <ul>
    103 <li>
    104 <code>msg</code>: name of message
    105 
    106 <li>
    107 <code>par</code>: parameters
    108 
    109 </ul>
    110 <li>
    111 notation: <img src="img/synchronous-message.png" alt="Synchronous message" />
    112 
    113 </ul>
    114 
    115 <p>
    116 asynchronous message:
    117 </p>
    118 <ul>
    119 <li>
    120 sender continues without waiting for response msg
    121 
    122 <li>
    123 syntax: <code>msg(par₁, par₂)</code>
    124 
    125 <li>
    126 notation: <img src="img/asynchronous-message.png" alt="asynchronous message" />
    127 
    128 </ul>
    129 
    130 <p>
    131 response message:
    132 </p>
    133 <ul>
    134 <li>
    135 can be omitted if content and location are obvious
    136 
    137 <li>
    138 syntax: <code>att = msg(par₁, par₂): val</code>
    139 
    140 <ul>
    141 <li>
    142 <code>att</code>: return value assigned to variable (optional)
    143 
    144 <li>
    145 <code>msg</code>: name of message
    146 
    147 <li>
    148 <code>par</code>: parameters
    149 
    150 <li>
    151 <code>val</code>: return value
    152 
    153 </ul>
    154 <li>
    155 notation: <img src="img/response-message.png" alt="response message" />
    156 
    157 </ul>
    158 
    159 <p>
    160 object creation:
    161 </p>
    162 <ul>
    163 <li>
    164 dashed arrow, arrowhead pointing to head of lifeline of object that's being created
    165 
    166 <li>
    167 keyword <code>new</code>
    168 
    169 <li>
    170 notation: <img src="img/object-creation-.png" alt="Object creation" />
    171 
    172 </ul>
    173 
    174 <p>
    175 object destruction:
    176 </p>
    177 <ul>
    178 <li>
    179 object is deleted
    180 
    181 <li>
    182 large cross at end of lifeline
    183 
    184 <li>
    185 notation: <img src="img/object-destruction-.png" alt="Object destruction" />
    186 
    187 </ul>
    188  
    189 <p>
    190 found message:
    191 </p>
    192 <ul>
    193 <li>
    194 sender unknown/not relevant
    195 
    196 <li>
    197 notation: <img src="img/found-message.png" alt="Found message" />
    198 
    199 </ul>
    200  
    201 <p>
    202 lost message:
    203 </p>
    204 <ul>
    205 <li>
    206 receiver unknown/not relevant
    207 
    208 <li>
    209 notation: <img src="img/lost-message.png" alt="Lost message" />
    210 
    211 </ul>
    212 
    213 <p>
    214 Time-consuming message:
    215 </p>
    216 <ul>
    217 <li>
    218 message with duration
    219 
    220 <li>
    221 usually messages transmitted instantly (by assumption); not in this case
    222 
    223 <li>
    224 notation: <img src="img/time-consuming-message.png" alt="Time-consuming message" />
    225 
    226 </ul>
    227 
    228 <div id="Sequence Diagrams-Combined fragments"><h3 id="Combined fragments">Combined fragments</h3></div>
    229 <p>
    230 model various control structures, have 12 predefined operators.
    231 </p>
    232 
    233 <p>
    234 Example:
    235 </p>
    236 
    237 <p>
    238 <img src="img/combined-fragment-example.png" alt="Combined fragment example" />
    239 </p>
    240 
    241 <div id="Sequence Diagrams-Combined fragments-Branches &amp; loops"><h4 id="Branches &amp; loops">Branches &amp; loops</h4></div>
    242 <p>
    243 <code>alt</code>:
    244 </p>
    245 <ul>
    246 <li>
    247 alternative sequence
    248 
    249 <li>
    250 like a switch statement, with guards selecting the path to be executed
    251 
    252 <li>
    253 guards modeled in square brackets, default true
    254 
    255 <li>
    256 guards have to be disjoint so that behavior is deterministic!
    257 
    258 </ul>
    259 <blockquote>
    260 <img src="img/alt-fragment.png" alt="Alt fragment" />
    261 </blockquote>
    262 
    263 <p>
    264 <code>opt</code>:
    265 </p>
    266 <ul>
    267 <li>
    268 optional sequence
    269 
    270 <li>
    271 like an if without an else
    272 
    273 <li>
    274 actual execution depends on guard
    275 
    276 <li>
    277 exactly one operand
    278 
    279 </ul>
    280 <blockquote>
    281 <img src="img/opt-fragment.png" alt="Opt fragment" />
    282 </blockquote>
    283 
    284 <p>
    285 <code>loop</code>:
    286 </p>
    287 <ul>
    288 <li>
    289 repeated sequence
    290 
    291 <li>
    292 min/max number of iterations - <code>(min..max)</code> or <code>(min, max)</code>. default <code>(*)</code>, no upper limit.
    293 
    294 <li>
    295 guard evaluated when min number of iterations took place, checked on each iteration. loop quits if false.
    296 
    297 </ul>
    298 <blockquote>
    299 <img src="img/loop-fragment.png" alt="Loop fragment" />
    300 </blockquote>
    301 
    302 <p>
    303 <code>break</code>:
    304 </p>
    305 <ul>
    306 <li>
    307 exception handling
    308 
    309 <li>
    310 one operand with a guard. if true:
    311 
    312 <ul>
    313 <li>
    314 interactions within operand are executed
    315 
    316 <li>
    317 remaining operations of <em>surrounding</em> fragment don't run
    318 
    319 <li>
    320 interaction continues at next higher level fragment (so like you skip a level)
    321 
    322 </ul>
    323 </ul>
    324 <blockquote>
    325 <img src="img/break-fragment.png" alt="Break fragment" />
    326 </blockquote>
    327 
    328 <div id="Sequence Diagrams-Combined fragments-Concurrency and order"><h4 id="Concurrency and order">Concurrency and order</h4></div>
    329 <p>
    330 <code>seq</code>:
    331 </p>
    332 <ul>
    333 <li>
    334 weak sequencing, default order of events
    335 
    336 <li>
    337 can't skip around on the same lifeline
    338 
    339 </ul>
    340 <blockquote>
    341 <img src="img/seq-fragment.png" alt="Seq fragment" />
    342 </blockquote>
    343 
    344 <p>
    345 <code>strict</code>:
    346 </p>
    347 <ul>
    348 <li>
    349 strict order
    350 
    351 <li>
    352 fixed sequence of events across lifelines
    353 
    354 <li>
    355 order of events on different lifelines between different operands is significant
    356 
    357 <li>
    358 messages in operand higher up on vertical axis are <em>always</em> exchanged before the ones that are lower
    359 
    360 </ul>
    361 <blockquote>
    362 <img src="img/strict-fragment.png" alt="Strict fragment" />
    363 </blockquote>
    364 
    365 <p>
    366 <code>par</code>:
    367 </p>
    368 <ul>
    369 <li>
    370 concurrent interaction
    371 
    372 <li>
    373 relax chronological order between messages in different operands
    374 
    375 <li>
    376 restrictions in each operand have to be respected
    377 
    378 <li>
    379 order of different operands is irrelevant
    380 
    381 </ul>
    382 <blockquote>
    383 <img src="img/par-fragment-.png" alt="Par fragment" />
    384 </blockquote>
    385 
    386 <p>
    387 <code>critical</code>:
    388 </p>
    389 <ul>
    390 <li>
    391 atomic interaction
    392 
    393 <li>
    394 make sure that certain parts of interaction aren't interrupted by unexpected events
    395 
    396 <li>
    397 <em>always</em> has to be in that order
    398 
    399 </ul>
    400 <blockquote>
    401 <img src="img/critical-fragment.png" alt="Critical fragment" />
    402 </blockquote>
    403 
    404 <div id="Sequence Diagrams-Combined fragments-Filters and assertions"><h4 id="Filters and assertions">Filters and assertions</h4></div>
    405 <p>
    406 <code>ignore</code>:
    407 </p>
    408 <ul>
    409 <li>
    410 irrelevant interaction
    411 
    412 <li>
    413 messages can occur at runtime but don't have other significance
    414 
    415 <li>
    416 one operand, irrelevant messages in curly brackets after keyword <code>ignore</code>
    417 
    418 </ul>
    419 <blockquote>
    420 <img src="img/ignore-fragment.png" alt="Ignore fragment" />
    421 </blockquote>
    422 
    423 <p>
    424 <code>consider</code>:
    425 </p>
    426 <ul>
    427 <li>
    428 relevant interaction with a particular importance
    429 
    430 <li>
    431 one operand. "dual" to ignore fragment
    432 
    433 <li>
    434 considered messages in curly brackets
    435 
    436 <li>
    437 and yes, you can use <code>ignore</code> instead of <code>consider</code> and vice-versa
    438 
    439 </ul>
    440 <blockquote>
    441 <img src="img/consider-fragment.png" alt="Consider fragment" />
    442 </blockquote>
    443 
    444 <p>
    445 <code>assert</code>:
    446 </p>
    447 <ul>
    448 <li>
    449 asserted interaction
    450 
    451 <li>
    452 mandatory interactions. the model is complete. can't have any deviations.
    453 
    454 </ul>
    455 <blockquote>
    456 <img src="img/assert-fragment.png" alt="Assert fragment" />
    457 </blockquote>
    458 
    459 <p>
    460 <code>neg</code>:
    461 </p>
    462 <ul>
    463 <li>
    464 invalid interaction
    465 
    466 <li>
    467 describe situations that must not occur
    468 
    469 <li>
    470 depicting relevant but <em>incorrect</em> sequences
    471 
    472 </ul>
    473 
    474 <p>
    475 <img src="img/neg-fragment.png" alt="Neg fragment" />
    476 </p>
    477 
    478 <div id="Sequence Diagrams-Further language elements"><h3 id="Further language elements">Further language elements</h3></div>
    479 <p>
    480 time constraints:
    481 </p>
    482 <ul>
    483 <li>
    484 point in time for event occurrence: <code>after(5sec)</code>, <code>at(12.00)</code>
    485 
    486 <li>
    487 time period between two events: <code>{lower..upper}</code>
    488 
    489 <li>
    490 <code>now</code>: current time
    491 
    492 <li>
    493 duration: calculation of duration of message transmission
    494 
    495 </ul>
    496 
    497 <p>
    498 Interaction reference:
    499 </p>
    500 <ul>
    501 <li>
    502 integrates one sequence diagram in another sequence diagram
    503 
    504 <li>
    505 define with <code>sd name</code> in the corner, then use the name in the diagram with <code>ref</code> in the corner
    506 
    507 </ul>
    508 
    509 <p>
    510 Gate:
    511 </p>
    512 <ul>
    513 <li>
    514 allows to send and receive messages beyond boundaries of interaction fragment
    515 
    516 </ul>
    517 
    518 <p>
    519 state invariant:
    520 </p>
    521 <ul>
    522 <li>
    523 asserts certain condition has to be true at certain time
    524 
    525 <li>
    526 if state invariant is not true, either model or implementation is wrong 
    527 
    528 <li>
    529 notations:
    530 
    531 </ul>
    532 <blockquote>
    533 <img src="img/state-invariant-diagram.png" alt="State invariant diagram" />
    534 </blockquote>
    535 
    536 </body>
    537 </html>