Uml Sequence Diagram - How to Represent Method Arguments That Instantiate Objects

UML sequence diagram - how to represent method arguments that instantiate objects

Basically you just show how and in which order the objects are instantiated and not where they are assigned:

Sample Image

So first the ThirdClass is created and then SecondClass where you pass a ThirdClass parameter.

I don't know the exact Ruby syntax. So the new is a place holder. Other languages require the class name, Python uses __init__, etc. But the dashed arrow line shows that's it's an object creation.

How to parameterize a UML sequence diagram and apply it to multiple object instances?

Use an Interaction with Parameters:
generic Interaction

Now we would like to reference the Lifelines of the main Interaction in the arguments of the InteractionUse. Unfortunately, in UML this is not possible, since arguments are ValueSpecifications and they cannot reference another modelelement.

However, NoMagic suggested and implemented an additional ValueSpecification, called ElementValue, that does exactly this. I think this would be a valuable addition to UML and hopefully it will be added some day. Up to then, only MagicDraw users can use this solution (as far as I know).

With this non standard element, we can model this:
Sample Image

The connection between the lifelines is now via the arguments for the parameters of the generic interaction. Technically the lifelines would not need to be explicitely covered by the Interaction Use, but I think that it makes sense to do it (shown in my tool with a non standard circle on the border of the Interaction Use).

Advantage:
compact and versatile solution, almost conformant to the standard

Disadvantage:
uses a non standard model element, currently only available to MagicDraw users.

How to represent a method call that's through inheritance in a sequence diagram? (Ruby)

Though my Ruby is a bit rusted, here's an approach. A class diagram would look like

Sample Image

(assuming that the "<" operator in Ruby is inheritance). ThirdModule is stereotyped with <<module>> since it's just a container for some operations and not a real class. This is no standard but something you need to introduce in the domain where you are modeling.

A call to inherited_method would look like

Sample Image

Note that tools like Enterprise Architect can not recognize the imported operations and will not offer them in the message list to FirstClass so you need to type it manually.

How do I model an object thats returned from a function call in a sequence diagram?

Sequence Diagrams doesn't require much detail about the object that is returned.

When an operation is performed in an object / class (rectangles), then, a returning dotted arrow should go back to the line and object where it came from.

uml sequence diagram returning value

If a value is returned (wheter an object or a simple type variable), its identifier should appear over the returning arrow.

Optional "return" tags can appear over the arrows that doesn't explicit return a value.

There are several tutorials on the web, I recommend:

http://www.agilemodeling.com/essays/umlDiagrams.htm

EDIT:

In Sequence Diagrams, The returned object type is indicated by an identifier in the text in each box, such as "user: User" or ":UserDAO".

Then, a complementary class diagram or object diagram, based on the given objects, can provide additional information to the actual Sequence Diagram,
using the same class identifier or object identifier,
example: "User" or "UserDAO".

Do not confuse the class identifier, with the instance identifier.

Note that in the given figure, some boxes skip the specific object instance identifier, or replace it with an asterisk character.

How to make method arguments visible in StarUML diagrams

  1. Go to Toolbox -> Sequence -> Stimulus.
  2. Drag from one object to another to create the stimulus line
  3. On the side you should see the Properties for the call
  4. In Name put the method name, i.e. saveResult
  5. In the Detail section you can specify arguments. Put the arguments there, i.e. int value
  6. If the arguments don't appear then change the properties of the Sequence Diagram. Change MessageSignature to NAMEANDTYPE

Sample Image

How to represent mutiple calls in Seq diagram

Please find below a sequence diagram describing the following seqeunce:
- Creation of an instance b of type B
- Creation of an instance a1 of type A
- Creation of an instance a2 of type A
- Call of the operation Foo defined on B with a1 as parameter
- Call of the operation Foo defined on B with a2 as parameter

Sample Image



Related Topics



Leave a reply



Submit