How to draw calls from constructors in UML sequence diagrams?

ぐ巨炮叔叔 提交于 2019-12-07 06:09:17

问题


I've seen multiple ways to draw constructors, namely like here with tails under them (function call) but more often like here without the tails and with no arrow returning (sometimes with the label <<create>>).

I'm aware that there are differences between UML1 and UML2 and I'm not sure if this is one of them, however either way I cannot find any references as to how I can represent method calls from the constructor of an object.

EDIT: Example java code below. Say oour entry point is foo(). The main thing that I'm curious about is how to draw the B() constructor.

class A {
    private B b;
    public foo() {
        b = new B(this);
    }
}

class B {
    public B(A a) {
        foo();
        a.bar();
    }
}

回答1:


This websequencediagrams script seems to capture your code

User->A: foo
A-->>+B: <<create>>
B->B: foo
B->A: bar
B-->>A:
A-->>User:

You can validate the notation against http://www.uml-diagrams.org/sequence-diagrams-reference.html

EDIT: And this is the same message sequence as drawn by Enterprise Architect




回答2:


UML specs (2.5 beta) says about that

An object creation Message (messageSort equals createMessage) has a dashed line with an open arrow head.

Figure 17.14 illustrates this:

But anyway you do it I would model each operation in its own sequence diagram. So I would model your code example above as such:



来源:https://stackoverflow.com/questions/27001842/how-to-draw-calls-from-constructors-in-uml-sequence-diagrams

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