UML Sequence Diagrams

Info This post has , please enjoy the discussion !

In this post we  show you how to model a behavior by means of Sequence Diagram through the Eclipse Modeling Framework and Papyrus.

Link If you don’t know how to use Papyrus to create models and diagrams look at this previous post

The example consists of three classes: ClassA, ClassB and ClassC.

sequence_shot1

ClassA contains an instance of ClassB, named bObject, and an instance of ClassC, named cObject.

We want to model the fact that the behavior associated to the ClassA::aOperation(integerParameter:Integer, stringParameter:String) consists of the invocation of bObject.bOperation(integerParameter) followed by the invocation of cObject.cOperation(stringParameter).

The described behavior corresponds to the following pseudocode.

ClassA {
  ClassB bObject;
  ClassC cObject;
  public void   aOperation(int integerParameter,String stringParameter){
     bObject.bOperation(integerParameter);
     cObject.cOperation(stringParameter);
  }
}

Right click on the ClassA model element in the model explorer view. Choose New Diagram -> Create New Sequence Diagram

sequence_shot2

Give a name to the diagram then start adding the first lifeline taking it from the palette on the right side.

In this example the first LifeLine shall represents the instance of the classifier which is actually performing the behavior. To this end you only have to name such Lifeline ‘self’.

In fact UML spec 2.5b1 page 607, about a Lifeline is said.
If the name is the keyword self, then the Lifeline represents the object of the classifier that encloses the Interaction that owns the Lifeline. Ports of the encloser may be shown separately even when self is included.

We therefore need to other lifelines each one representing the ClassA attributes involved in the behavior. To this end click on the ‘…’ to give a value to the ‘represents’ attribute of the lifeline. It is in the right side of the properties tab as you can see in the picture ahead. Then choose the connectable element you want the lifeline to represent, in our case the ClassA’s bObject attribute.

sequence_shot3

do the same thing for the cObject attribute and you’ll have the three lifelines you need.

sequence_shot4

You can now start drawing messages.

In our example we deal with synch messages. Chosse the Message Synch element from the palette and draw an edge starting from the left border of the diagram and ending into the self lifeline. This will represent the invocation to the aOperation operation.

The starting point of this edge is called Gate.

According to the UML spec 2.5b1

A Gate is a MessageEnd which is used on the boundary of an Interaction, or an InteractionUse, or a CombinedFragment to establish the concrete sender and receiver for every Message 

We now have to specify the signature for this message as it is not generic but represents the invocation to the aOperation operation from an outside caller.

Push the ‘…’ button to give a value to che signature attribute in the properties tab as depicted in the figure ahead. Than choose the operation you want to be represented in the dialog that wil pop up.

sequence_shot5

and here you go. On the top of the edge you will see  the whole signature depicted.

sequence_shot6

Now note that in the UML 2.5b1 specification at page 663 is written that

In the case when a Message with messageSort synchCall or asynchCall has a non empty Operation signature, the arguments of the Message must correspond to the in and inout parameters of the Operation. A Parameter corresponds to an Argument if the Argument is of the same Class or a specialization of that of the Parameter.

Also

In the case when a Message with messageSort reply has a non empty Operation signature, the arguments of the Message must correspond to the out, inout, and return parameters of the Operation. A Parameter corresponds to an Argument if the Argument is of the same Class or a specialization of that of the Parameter. 

Thus I guess (But I am going to check this !) you should add an argument for each parameter. By pressing the + button on the top of the Arguments box.

However it seems that this is an open issue as Arguments are, at now, ValueSpecification and can thus only represent constant values and not refer to variables or parameters (see http://www.omg.org/issues/uml2-rtf.open.html#Issue8761,http://www.eclipse.org/forums/index.php/t/452139/). I hope to see this problem solved in the 2.5 specification.

Thus skip this step (at least for now) and add a BehavioralExecutionSpecification to the self lifeline in order to depict the behavior context of execution of the aOperation.  Then add another synch message from the aOperation behavior execution specification to the bObject lifeline. As the bObject as an associated classifier (ClassB) the following dialog will pop up

sequence_shot7

It basically asks you if you want to pick an already existing operation from the classifier, add a brand new operation to it, or just represent a not existing one. If you press the ‘…’ button you can browse among the ClassB’s operations and choose the bOperation. After that you will notice the following box in the bottom right corner. Choose BehaviorExecutionSpecification and proceed.

sequence_shot8

Continue in this way and model the flow of operations. In order to represent operations’ results draw edges with Message Replies. In this case the signature of the message shall be the same of the related operation.

In fact, according to the UML spec. 2.5b1 page 608

if the Message signature is an Operation, then …

…  If the messageSort is reply, then the Message represents the return from a synchronous call to the Operation. The arguments of the Message correspond to the out, inout and return ownedParameters of the Operation, in the order of the ownedParameters 

At the end of your design you should came up with something like this

sequence_shot9

No we only have to associate the modeled interaction (see it under the classifierBehavior node of the ClassA element) to the aOperation.

To this end click on the aOperation and press the + button on the top of the Method box in the properties as depicted in the figure ahead.

sequence_shot10

choose the defined interaction (sequence diagram)

sequence_shot11

sequence_shot12

The Method attribute represents the Behavior, in our case the Interaction, that implements the Operation. You can se the Behavior as a method body and the Operation as a method signature.

sequence_shot13

Heads Up!

If you have found this post useful please consider to share it with your friends

and to reccomend it on Google

thank you !!!

blog comments powered by Disqus