Chapter 5
Sequence diagrams
Here is an example of sequence diagram you can draw:
Now, we will talk about elements that compose such diagrams.
5.1 To define a sequence diagram
Here is the main difference from previous diagrams: to define a sequence diagram, you have to use a
5.2 To define an object
5.2.1 Types of objects
You can define an object with the
The default type is a class instance. You can give the class name with the
On the contrary, you may want to hide the double dots and not giving a class:
The
UML objects may be used in other contexts than class instances. Then, the colon symbol shown in an object
may not be necessary. For this purpose, you may use the
5.2.2 Automatic placement of an object
Both options
- The default value of the
y option is 0, that means the default placement of an object is at the top of the sequence diagram. - The default value of the
x option is the product of 4 by the value of the global counter identifying the object: for instance, for the second object defined in a diagram, thex option is set to 8 by default, …
Unless the width of the object is too large, a shift of 4 is enough. If not, you use the
5.2.3 To scale an object
The
5.3 To define a function call
Function calls are the core of sequence diagrams. Then, we need a motor either smart enough to propose a satisfacting default behavior, either easy enough to parametrize.
From a technical point of view, and I open here a parenthesis, there are two ways to implement function calls:
- Either we use the nodal matrix structure of
TikZ . The advantage is to work on a pre computed nodal grid and then to place elements of a sequence diagram easily (and fast for compilation) with exactly one counter. - Either we use an automatical positioning of nodes with a set of coordinates, here the time instant, that allows total freedom for the user and make its work easier.
I chose the second way, to keep the philosophy used to implement the other diagrams in this package. Indeed, if the lack of a grid needs a more accurate computation core, and as a result more compilation time, you can define most of the elements very easily, such as constructor calls, drawn according to the standard. That is different from others UML softwares I used before. I close the parenthesis.
5.3.1 Basic / recursive calls
You can define a function call with the
You have to give the name of the source object and the name of the destination object. If you give the same
name as source and destination, you define a recursive call. In this case, you may prefer use an alias, the
Of course, you can define
5.3.2 To place a call
The
You can also set spaces for recursive calls with the
5.3.3 Synchron / asynchron calls
The
5.3.4 Operation, arguments and return value
You can give the function name in a call and its arguments with the
You can also set the return value with the
In this case, the return arrow is drawn with the return value above. You can draw the return arrow without
giving a return value. For this, there is the
In some cases, the call may have multiple return arrows. To draw an additionnal return arrow, you can do as follows:
5.3.5 To define a constructor call
Constructor calls are special function calls, insofar as they build a new object. They are not messages between two lifelines, but between a lifeline and an object.
To define a constructor call, you can use the
You can notice that everything behave normally after a constructor call.
As an object builder, the
As a function call, it has the
5.3.6 To name a call
The
5.4 To define a combined fragment
Combined fragments are the second family of elements in a sequence diagram, with the function calls. You can
define them with the
5.4.1 Informations of a fragment
The
The
The
5.4.2 Name of a fragment
You can give a name to a combined fragment with the
5.4.3 To define regions of a fragment
Let’s take a alt fragment. It represents a switch-case instruction block. To represent each case, you need to set
regions in the fragment. For this purpose, you can use the
5.5 To change preferences
Thanks to the
-
text: - allows to set the default text color (=black by default),
-
draw: - allows to set the default color of edges and arrows (=black by default),
-
fill object: - allows to set the default background color of objects (=yellow !20 by default),
-
fill call: - allows to set the default background color for calls (=white by default),
-
fill fragment: - allows to set the default background color for fragments (=white by default),
-
font: - allows to set the default font style (=
\ small by default), -
object stereo: - allows to set the default font style (=object by default),
-
call dt: - allows to set the default font style (=auto by default),
-
call padding: - allows to set the default font style (=2 by default),
-
call type: - allows to set the default font style (=synchron by default),
-
fragment type: - allows to set the default font style (=opt by default),
-
fragment inner xsep: - allows to set the default font style (=1 by default),
-
fragment inner ysep: - allows to set the default font style (=1 by default),
-
create call dt: - allows to set the default font style (=4 by default)
You can also use the options
There is an exception:
5.6 Examples
5.6.1 Example from introduction, step by step
Definition of objects
Definition of the call opa and its components
Definition of the calls following the construction of E
Definition of fragments
5.7 Known bugs and perspectives
- When you define a fragment on a set of calls just after a constructor call, the automatic shift does
not work. You have to use the
dt with a value greather than 7 to the first call inside the fragment. - The automatic placement of objects with a multiple of 4 is not very convenient. A shift of 4 relatively to the last object drawn should be better.
- You can not give arguments to constructor calls.
- You can not force the drawing of the activity area of a "non working" object.
But you can lengthen lifelines thanks to
umlsdnode command: