Search code examples
umldiagramsequence-diagram

UML sequence diagram: How to draw creating an array of objects?


In a UML sequence diagram, how do I draw the process of creating an array of objects? E.g. (simplest case):

object1.function = function() {
    return [new Object2(), new Object2()];
};

I presume that I just add new participants in order (as in the diagram below), is that correct? But is there any way to emphasize that they are elements of an array?

Thanks in advance.

UML diagram

var Object1 = function() {};
var Object2 = function() {};
var object1 = new Object1();
object1.function = function() {
    return [new Object2(), new Object2()];
};
alert( object1.function() );  // [object Object],[object Object]

Solution

  • Yes, it's simply that you draw two life lines in your example. Each represents one of the returned instances.

    However, if you are creating many instances at once it would in most cases be enough to show a single instance as life line and add a note about the remaining ones. I would refrain from artificial presentation of some stack-like instance blocks. It would be possible when you use stereotyped and define the representation in a guideline along with the profile. That depends on your business domain. I usually stick to Occam.