Including a create message inside a combined fragment in sequence diagram

245 views Asked by At

I am working on my assignment about sequence diagrams. my question is if can we include a creation or deletion message in a combined fragment

2

There are 2 answers

0
qwerty_so On BEST ANSWER

In short: yes. You can do that with no issue.


In more detail: try to stick to UML rules but don't get blocked by just looking into the law book. Of course it's best to not violate the rules set up by the UML gods. But like when you are standing a red cossing light at night where you can see and hear nobody else, then what would hinder you to cross the street anyway?

One common mistake seen so often is to forget putting join nodes in ADs which will make the whole network get stuck at a particlar action. Yes, wrong. But basically only to machines and most people can read the meaning witout any issue. Only the lawyers will pick that up as being wrong.

So to sum up: when you model something and you feel that it transports the message then it's okay. Even when being not 100% correct. Strive for correctness but don't let it block you from doing the job. If you raise discussion it ain't bad. Not at all! Models are meant to discuss about something. So if your model got a discussion started it's even better. You can always ask for advice and fix it later.

0
Christophe On

In short

Yes you can do this, but you have to be careful about that the interaction remains consistent.

More details

Nothing prevents you from using an object creation or an object deletion in a combined fragment. In fact, there are even examples in the UML 2.5.1 specs: fig. 17.14 page 588 shows sequence diagram with a combined alt fragment in which a participant to the interaction is created and deleted.

If the syntax has no issue, it's nevertheless up to you to ensure the semantic consistency of your sequence diagram. In this regard, there are several pitfalls. For example:

  • if you create a participant in an alt or an opt fragment, but outside of this fragment this new participant would interact with other instances, you'd assume that the creation always takes place, whereas your fragment might not guarantee that.
  • if you'd have some complex sequencing with conditionals and loops, you'd better make sure that no message is send to a participant that might be created later.

There are also some ambiguities to better avoid. Creating a participant in a loop could be ambiguous, if this creation would happen at each iteration of the fragment: are new objects created in each iteration? If there's not destruction in the loop, do the other participants created in previous iteration still exist? If the lifeline has interactions after the loop fragment, is if for the first, or the last object created? etc...