How to show “if” condition on a sequence diagram?

前端 未结 4 2085
抹茶落季
抹茶落季 2020-11-27 10:04

I was wondering, how can one represent \"if\" statement on a sequence diagram?

if (somethingShouldBeDone) {
       // Do it
} else {
       // D         


        
相关标签:
4条回答
  • 2020-11-27 10:32

    Very simple , using Alt fragment

    Lets take an example of sequence diagram for an ATM machine.Let's say here you want

    IF card inserted is valid then prompt "Enter Pin"....ELSE prompt "Invalid Pin"

    Then here is the sequence diagram for the same

    Hope this helps!

    0 讨论(0)
  • 2020-11-27 10:34

    If else condition, also called alternatives in UML terms can indeed be represented in sequence diagrams. Here is a link where you can find some nice resources on the subject http://www.ibm.com/developerworks/rational/library/3101.html

    branching with alt

    0 讨论(0)
  • 2020-11-27 10:42

    If you paste

    A.do() {
      if (condition1) {
       X.doSomething
      } else if (condition2) {
       Y.doSomethingElse
      } else {
       donotDoAnything
      }
    }
    

    onto https://www.zenuml.com. It will generate a diagram for you.If/else sequence diagram

    0 讨论(0)
  • 2020-11-27 10:50

    In Visual Studio UML sequence this can also be described as fragments which is nicely documented here: https://msdn.microsoft.com/en-us/library/dd465153.aspx

    0 讨论(0)
提交回复
热议问题