constructor in UML sequence diagram

青春壹個敷衍的年華 提交于 2019-12-10 19:37:00

问题


what is the meaning of the following sequence diagram and exactly the constructor(that is represented as a create object)?


回答1:


It means that ClassA instantiates ClassB. The arrow represents that the constructor of ClassB is called by ClassA




回答2:


The message's name "Class B()" is wrong : it should be "create".
Is that what confusing you ?




回答3:


Chriss, hopefully you've figured it out by now. Please accept Cratylus's answer as it is correct.

Here is an example in Java:

Main.java

package com.example.umlquestion;

// (e.g. your application that makes and uses an instance of ClassA)
public class Main {
    public Main() {
        // this calls ClassA's constructor, which will then call ClassB's constructor
        private ClassA instanceA = new ClassA(); 
        // ...
    }
}

ClassA.java

package com.example.umlquestion;

public class ClassA  {
    private ClassB instanceB;
    public ClassA() {
        instanceB = new ClassB();
        // ...
    }
    // ...
}

ClassB.java

package com.example.umlquestion;

public class ClassB  {
    public ClassB() {
        // ...
    }
    // ...
}


来源:https://stackoverflow.com/questions/15012587/constructor-in-uml-sequence-diagram

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