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

左心房为你撑大大i 提交于 2019-11-26 12:51:11

问题


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

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

Can it be represented at all? The thing is ... in my code, fair amount of conditions are checked to determine a variety of actions. If i am going to show the actions, I\'d like to explicitly state that actions are caused by particular events.

If possible create an image representation of a solution.


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/8114770/how-to-show-if-condition-on-a-sequence-diagram

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!