Is there a rule/guideline about how to display a C# using() statement in UML sequence diagrams?

I'm right now in the last months of my apprenticeship. And to prove, that I'm able to develop software from start to beginning, I have to do a project which has to have a documentation. This documentation will be shown to a jury to rate it.

My thought was to create an activation adding a note to it, saying using(CmSdkScope scope = new CmSdkScope), and then adding another activation - like a self call - to it, where I then message other classes.

Here is an example: enter image description here

Is this valid?

  • 8
    Why... I mean, if you’re going to write code, go write code. – Telastyn Mar 20 '18 at 11:28
  • 2
    Code is documentation. Create those uml diagrams from from code. It's madness to try and create them by hand before you actually write your code. – David Arno Mar 20 '18 at 11:37
  • 1
    In that case, create whatever diagrams you need to help you understand how your design might work. Since they are for you, do not worry about "proper" UML; draw whatever what makes sense to you. Then throw those diagrams away before you start coding, please. – David Arno Mar 20 '18 at 11:46
  • 5
    If you are doing this as part of an end of apprenticeship test, then you should be asking your boss, others in your team (if applicable) and the jury (if possible) what they'd do in this situation. This both shows a willingness to ask for help and you're more likely to get an answer that fits in with the company's approach to such things. Asking random folk on the internet for help in such a specific situation will rarely yield a good answer. – David Arno Mar 20 '18 at 12:22
  • 4
    "Asking the jury is not possible, same for my boss". Really, why on earth can you not ask your boss? They are utterly failing in their duty to help you develop and grow as a useful member of the team if they cannot or will not answer such questions. – David Arno Mar 20 '18 at 12:32

Disclaimer: I'm not a C# programmmer, but I looked at the documentation that shows a simple example:

using (Font font1 = new Font("Arial", 10.0f)) 
    byte charset = font1.GdiCharSet;

Here's how I'd show this in UML:

enter image description here

What's key to show is that there is a temporary scope. So, it's a rare case where the "X" (end of life of an object) is used in UML sequence diagrams.


This depends on a lot of factors.

If you want to use the sequence diagram to generate code from it, then most tools will not understand this kind of double activation. In that sense, it is not valid.

If it is important to show the lifetime of the CmSdkScope object, then just a comment explaining that an activation bar corresponds to a using() statement is too subtle for by taste. Then I would explicitly draw the creation and destruction of the CmSdkScope object and possibly leave the fact that this is realized with a using statement as an implementation detail.

In most other cases, I would say that it is a perfectly understandable sequence, so I would call it valid.

  • This answer says what @Furmanator answer shows. but I like the additional reasoning And, this question succinctly answers the OP question "is this diagram artifact valid?" – radarbob Mar 23 '18 at 22:51

You could use an interaction frame to represent a using block. They can be used to denote loops and conditionals; this is a bit different, but it lends itself well for this kind of representation, IMO.

Interaction frames

Take a look at this for more detail: UML Sequence Diagrams

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.