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:
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:
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:
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
(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
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.
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
- Go to Toolbox -> Sequence -> Stimulus.
- Drag from one object to another to create the stimulus line
- On the side you should see the Properties for the call
- In Name put the method name, i.e. saveResult
- In the Detail section you can specify arguments. Put the arguments there, i.e. int value
- If the arguments don't appear then change the properties of the Sequence Diagram. Change MessageSignature to NAMEANDTYPE
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
Related Topics
Expressing Conditional Haml Possibly with Ternary Operator
Validates Presense VS Null False in Rails Models/Tables
How to Escape the Vertical Bar When Doing Command Line with Ruby
How to Speed Up Ruby/Rake Task
Currying a Proc with Keyword Arguments in Ruby
How to Turn Off Bigint Primary Keys in Rails 5.1
Rails Object#Blank? VS. String#Empty? Confusion
Initializing a Hash with Empty Array Unexpected Behaviour
Chromedriver Devtools Port Number Error
Ruby: Wait for All Threads Completed Using Join and Threadswait.All_Waits - What the Difference
Where Does Rails Store Data Created by Saving Activerecord Objects During Tests
Rmagick How to Convert Image in Memory
How to Override the System Timezone in Ruby
What Is a More Ruby-Like Way of Doing This Command
Bootstrap Modal in Ruby on Rails Not Working
How to Count Duplicates Hash Itens in Ruby 1.8.5 ( Sketchup Ruby API )