![uml sequence diagram if then else uml sequence diagram if then else](https://i.pinimg.com/originals/66/c1/62/66c162c1e0c8a3506490054f1d8836c9.png)
![uml sequence diagram if then else uml sequence diagram if then else](https://www.conceptdraw.com/How-To-Guide/picture/UML-sequence-diagram-template.png)
What are Sequence Diagrams?įor those of you who haven't been exposed, sequence diagrams describe a series of messages in a sequence between different objects. Mermaid.js is available in a variety of tools, but I most frequently use it in GitHub markdown files and in Polyglot Notebooks. It also means that the diagram source is easily version-controlled and anyone on your team can modify it without special tooling or licenses. This means your time is focused on actually writing the interaction logic instead of generating a visual. With Mermaid.js you can write a few lines of text and use its JavaScript library to generate a professional sequence diagram like the one below: Mermaid.js is the solution I needed 20 years ago. I distinctly remember working on sequence diagrams in my undergraduate computer science education and having so many issues trying to get the various boxes and arrows to look standard, rearrange shapes as I needed to expand the diagram, and generally focusing on anything but the logic the diagrams intended to create. Previously I've shown how Mermaid.js allows you to create entity relationship diagrams and class diagrams, but in this article we'll cover a far more complex diagram: the sequence diagram. But for "simple" exception handling, I think a break is a better way to represent it, then alt.I've been really enjoying seeing how Mermaid.js lets you generate technical diagrams from simple markdown. ConclusionĪs always, the best method depends on the scenario.
![uml sequence diagram if then else uml sequence diagram if then else](https://i.stack.imgur.com/xog73.png)
This is ofcourse a very simple example, and you can have a lot more interaction in the break interaction operator, like logging or transaction handling. I think it even makes things better, because you can see where a sequence stops when an exception occurs. What I like about this way of displaying exception handling is that it makes the diagram much less cluttered. In this example the exception isn't caught until it enters the UI, in this case the ATM. Using a break interaction operator, it would look something like this: Let's take a look when the situation when something happens, what causes the ATM to decline de withdrawal. When the guard condition is true, the current interaction run is abandoned and the clause in the break interaction operand runs. The break interaction operator is similar to the break mechanism in other programming languages. This looks nice, for a small diagram, but once the diagram starts to grow and you get a lot of nested alt interaction operations, you might start to loose the overview. Using an alt interaction operator, it would look something like this: The else clause of the alternative combined fragment runs when no other option is selected. If there is no guard, the operand always runs when it is selected. However, as for any operand, the selected operand in the alternative structure runs only if the guard condition tests true. Only one of the offered alternatives runs on any pass through the interaction. The server confirms the withdrawal is approved and, the service passes this on to the ATM's UI and the ATM dispenses the money.Īn alternative interaction operator represents the logic equivalent of an if-then-else statement. The customer enters the data, the ATM calls a service, which calls the bank's server.
![uml sequence diagram if then else uml sequence diagram if then else](https://i.stack.imgur.com/ceoGs.png)
I'll describe both methods using a classical example: withdraw money from an ATM when the balance is too low. They both use interaction operators, alt and break. 1Īfter searching for quite a while on how to model exception handling in a UML Sequence Diagram I found two ways to represent exception handling in a UML Sequence Diagram. There are several proposed notations for exception handling. Some clumsy approaches to model try-catch blocks are by utilizing combined fragments - alt (alternatives) and breaks, while adding stereotypes for reply messages representing thrown exceptions. UML provides neither notation to model exception handling in sequence diagrams nor any reasoning why it is absent.