As far I as I could tell, the proper way to show an object creation in a sequence diagram is with an asynchronous arrow, e.g.,
However, in Java (and other OO languages I have used), as far as I know, a new()
operation is blocking.
I noticed that some references (Craig Larman) use a hybrid message (dotted line with filled arrow), e.g.,
Especially when a constructor is involved, it's important that a create
be a synchronous call. That is, it will return when the constructor is finished. According to my understanding of asynchronous messages in UML, the :A
object would not wait for the constructor of :B
to finish.
My students often ask this question, and I suspect there is some history behind this. I'm curious why there is this seeming inconsistency.
-
1Do they also ask about UML inheritance letting an object change type including having base classes added with state changes? Personally I have never found UML useful other than giving me a set of shapes I can draw with....... And most programmer has no concept of the meaning of most UML symbols, so UML is little more than a set of class diagrams on most projects.Ian– Ian2019年12月03日 17:59:57 +00:00Commented Dec 3, 2019 at 17:59
-
UML predates Java/C# being in common use.Ian– Ian2019年12月03日 18:00:53 +00:00Commented Dec 3, 2019 at 18:00
1 Answer 1
Each UML message in an interaction diagram has a unique MessageSort
, which are mutually exclusive (section 17.4.2):
synchCall
asynchCall
asynchSignal
createMessage
deleteMessage
reply
The graphical notation of the message is defined depending on MessageSort
(section 17.4.4.1):
- An asynchronous Message (messageSort equals asynchCall or asynchSignal) has an open arrow head.
- A synchronous Message (messageSort equals synchCall) has a filled arrow head.
- A reply Message (messageSort equals reply) has a dashed line with either an open or filled arrow head.
- An object creation Message (messageSort equals createMessage) has a dashed line with an open arrow head.
- An object deletion Message (messageSort equals deleteMessage) must end in a
- ...
So, this graphical representation is a convention and you shall not be mislead to derive a semantic from it ! If you see a « create »
message with an open arrow head, it's not because it would be asynchronous, but simply because that's the way UML decided to represent the creation.
I agree that it's ambiguous: it looks like a reply message, and it's not consistent with the meaning given to arrow heads. Maybe some improvement to suggest to the UML standard committee ? The market didn't wait: there are already some tools that use normal synchronous message arrows.
-
1UML has so many versions now I just laugh when people call it a standard.candied_orange– candied_orange2019年12月03日 21:02:44 +00:00Commented Dec 3, 2019 at 21:02
-
This explains why I got an unexplained downvote on my question (i.e., shame on you for deriving a semantic from the symbols).Fuhrmanator– Fuhrmanator2019年12月03日 21:16:36 +00:00Commented Dec 3, 2019 at 21:16
-
@candied_orange I was talking about this UML 2.5.1 specification approved by OMG who has authority on it. I admit calling it abusively a standard, since the official standard is ISO 19505, which corresponds to UML 2.4.1. The differences are minor: 198 CHF (the cost of the older ISO standard compared to the free up-to-date OMG specification) ;-)Christophe– Christophe2019年12月03日 23:10:53 +00:00Commented Dec 3, 2019 at 23:10
-
2Unfortunately I've been subjected to so many misused undefined indecipherable UML dodads that I don't trust that I know what I'm looking at until I beat it out of some one. I'm with the students. "Huh?"candied_orange– candied_orange2019年12月03日 23:24:55 +00:00Commented Dec 3, 2019 at 23:24
-
1@candied_orange I'm with the students: "OMG!" :)Fuhrmanator– Fuhrmanator2019年12月04日 04:50:15 +00:00Commented Dec 4, 2019 at 4:50