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

Jiew Meng picture Jiew Meng · Nov 4, 2011 · Viewed 22.9k times · Source

Suppose I have code like

user = AuthHandler.getLoggedInUser()
user.setName(name)
UserDAO.update(user)

How will the sequence diagram look like?

I did

Is it correct? the user/userDAO part?

Answer

umlcat picture umlcat · Nov 4, 2011

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.