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.
You should try to replicate the operations described in this section
before moving on to
Your Job.
After launching Violet, either click
sequence diagram on the
opening screen or use the
File → New menu option to get:
Under
Diagram tools select
Object lifeline and click in
the drawing area to create an empty box.
Right click on the box to get a dialog that accepts the object's name.
In this case an object named
aFoo of type
Foo is being created:
An activation bar represents a method call on an object.
To create one select the
Activation bar tool and click on an
object's lifeline.
Below two objects with activation bars have been created.
Note that at this point 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 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. (Note that you can also change the note's background color.)
In this case we are indicating the
Foo method that is
represented by
aFoo's activation bar:
To connect the note to a specific point in the diagram, select
the
Note connector tool and drag from the note to the specific point:
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 calling
aBar's
method
someBarMethod with
value 1 being returned.
Select the
Call / Create message tool 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:
Right click the connecting line to get a dialog that accepts the name
of the method being called, with or without arguments:
Select the
Return message tool 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:
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.
There does not appear to be any good way to indicate the return value
of a self call in Violet.
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 / Create message tool and drag from the object's
upper activation bar down to the lower activation bar that was just created:
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:
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
value 1 is not equal to
zero.
Note that a second activation bar has been added to
aBar's
lifeline before making the connection:
Sometimes a sequence diagram needs to model the creation of an object.
In this example the object
aBaz of type
Baz is created
during execution of
aBar's method
anotherBarMethod.
First create the new object's lifeline using the
Object lifeline
tool.
Do not create an activation bar for the new object.
Using the
Call / Create message tool connect the activation bar
of the method that creates the new
object directly to that object:
Upon release of the mouse, Violet will realign the object to indicate
its creation.
It will also automatically label the connection with
the
«create» stereotype:
Draw a diagram that models the
Console.processMoves() method
from the problem solving framework provided in
Assignment 2.
The
framework.Console class is shown below.
You should show all calls except to
System.exit().
Your calls should show all arguments and return values.
Save your diagram as
CS2511_Lab_4.
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.