Chriss
Chriss

Reputation: 995

constructor in UML sequence diagram

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

enter image description here

Upvotes: 4

Views: 8518

Answers (3)

jacobq
jacobq

Reputation: 11587

Chriss, hopefully you've figured it out by now.

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() {
        // ...
    }
    // ...
}

Upvotes: 2

Sylvain H.
Sylvain H.

Reputation: 133

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

Upvotes: 4

Cratylus
Cratylus

Reputation: 54094

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

Upvotes: 3

Related Questions