In this lab you will practice creating sequence diagrams with Violet, the same diagramming tool you used in the previous lab exercise.
This section describes most of the sequence diagram operations that you can perform in Violet.

The examples here assume the class relationships shown below. The diagram gives names and signatures of methods, but nothing about how the methods behave.

Sequence diagrams are intended to model how methods behave.

After launching Violet, click File > New > Sequence Diagram to get the tool window below.

Under Diagram tools select the Object Lifeline icon on the tool bar:

This object represents the implicit parameter in a method call. That is, it is the object in a method calling expression like "object.method(arg1, ... argn)".

Click in the drawing area to create an object, then right click on the object to get a dialog that accepts the object's name.

Below an object named aFoo of type Foo has been created. Note the "lifeline" extending just below the rectangle representing the object:

An "activation bar" represents a method call on an object.

To create one select the Activation bar icon on the tool bar:

then click on an object's lifeline.

Below two objects with activation bars have been created.

Note:

In the diagram below it is assumed that aFoo's method exits before aBar's method starts.

Sequence diagram notes provide information and make diagrams easier to read.

They are created in the same way class diagram notes are created.

Select the Note tool (it looks the same as that for class diagrams) and click where you want the note to appear in the diagram.

Right click the note to get a dialog accepting the text of the note.

Then use the Note connector tool (again, the same as for class diagrams) to connect the note to the diagram.

In this case we are indicating that aFoo's activation bar represents the calling of aFoo's method "someFooMethod".

To show how objects collaborate to produce a result, sequence diagrams model method calls, which can be thought of as sending a message from one object to another.

This example will show aFoo's method someFooMethod calling aBar's method someBarMethod with an int value being returned.

Select the Call icon from the tool bar:

and drag from the calling object's activation bar to the receiving object's activation bar:

Upon release of the mouse, Violet will realign the objects' activation bars as shown below.

The realignment indicates that the body of someFooMethod calls a method on the object aBar.

Right click the connecting line to get a dialog that accepts the name of the method being called (as the middleLabel property), with or without arguments:

Select the Return icon from the tool bar:

and drag from the receiving object's activation bar to the sending object's activation bar.

Right click the connecting line to get a dialog that accepts the value being returned (again, use the middleLabel property):

Sometimes it is necessary to model an object calling its own method.

In this example we show aFoo's method someFooMethod calling its own method anotherFooMethod.

Start by creating a new activation bar for the object that is doing the self calling by using the Activation bar tool.

Hang the new activation bar on the activation bar of the method that is doing the self calling:

Select the Call tool and drag from the top activation bar to the lower activation bar:

Upon release of the mouse, Violet will redraw the connection as a self call:

Right click the self call connection to get a dialog accepting the name of the method being called:

There does not appear to be any good way to indicate the return value of a self call in Violet.

To indicate conditional method calls, simply label the call line with a prefix "[condition]" where condition is a boolean valued expression.

Below, aFoo calls aBar's method anotherBarMethod only if val is not equal to zero.

Note:

Sometimes a sequence diagram needs to model the creation of an object.

In this example the object aBaz is created during execution of aBar's method anotherBarMethod.

Upon release of the mouse, Violet will realign the object to indicate its creation:

Recall that the class diagram for our example is shown to the right.

The sequence diagram below provides the following information about the behavior of the class Foo's method someFooMethod:

Consider the simple classes shown below and draw a diagram that models the interaction launched by the call "aFoo.fooMethod1(aZowie);" in class Foo's main method.

Your calls should show all arguments and return values. Since aFoo and aZowie are initialized in main before the call to fooMethod1, your diagram should start like this:

Save your diagram as Sequence. Violet will actually create the file Sequence.violet.

Submit your CS2511_Lab_4.sequence.violet file to the webdrop folder for this class by going to

Note that the grader will open your diagram in Violet.