Working with Communication Diagram

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
SOFTWARE ENGINEERING DEPARTMENT
Lab # 08
Working with Communication Diagram
You’ll learn in this Lab:



What a communication diagram is
How to apply a communication diagram
How to model active objects, concurrency, and synchronization
What Is a Communication Diagram
An object diagram shows objects and their relationships with one another. A communication
diagram is an extension of the object diagram. In addition to the links among objects, the
communication diagram shows the messages the objects send each other. You usually omit the
names of the links because they would add clutter.
One way to think of the relationship between the object diagram and the communication diagram
is to imagine the difference between a snapshot and a movie. The object diagram is the snapshot:
It shows how instances of classes are linked together in an instant of time The communication
diagram is the movie: It shows interactions among those instances over time.
To represent a message, you draw an arrow near the link between two objects. The arrow points
to the receiving object. A label near the arrow shows what the message is. The message typically
tells the receiving object to execute one of its (the receiver's) operations. Arrowheads have the
same meaning as in sequence diagrams.
Software Design and Architecture
4th Semester-SE
UET Taxila
Figure 10.1 The Symbol set for Communication diagram
Cars and Car Keys
We start again with the domain of cars and car keys. The class diagram in Figure 10.2is just a
refresher for you,The idea is to remind you about the operations and signals, so you know the
messages each object can receive.
Figure 10.2 The domain of cars and car keys.
Software Design and Architecture
4th Semester-SE
UET Taxila
Next, we create an object diagram that models instances of the classes in Figure 10.2. This
diagram appears in Figure 10.3and is the foundation for a communication diagram.
Figure 10.3. An object diagram that models instances of the classes in Figure 10.2.
Now you can add the messages. This figure shows one way of dealing with multiple messages
that pass between two objects. As you can see, messages 4 and 5 are signals that go from the Car
to theCarOwner. They have separate labels but not separate arrows.
Software Design and Architecture
4th Semester-SE
UET Taxila
Figure 10.4. A communication diagram that models the messages that pass between the objects in Figure
10.3
The intent is to keep the diagram from becoming too busy. Some modeling tools, however,
provide a separate arrow for each message. Bear in mind that if different kinds of messages pass
between the same two objects, you have to show both arrows.
Figure 10.5. The communication diagram and the equivalent sequence diagram for the car and car key
example.
Changing States and Nesting Messages
Suppose Car has an attribute, locked, whose values are either true or false. You can imagine two
states, Locked and Unlocked for Car, as shown in Figure 10.6.
Software Design and Architecture
4th Semester-SE
UET Taxila
Figure 10.6. Modeling the Unlocked and Locked states of a car.
You can show a change of state in a communication diagram. To do that in this example, you
show the value of lockedin the Carobject. Then, you duplicate the Carobject with the new value
of locked. Connect the two, and then show a message going from the first to the second. Label
the message with the keyword «become».
This example gives you the chance to examine an additional concept related to communication
diagrams—using the numbering system to show something about the relationships among
messages. So far, you've only seen messages in sequence. It's also possible to show one message
nested in another. You number the nested message by starting it with the number of the message
it's nested in, then a decimal point, and then a number for the nested message. Figure 10.7shows
the state change and the nesting.
Software Design and Architecture
4th Semester-SE
UET Taxila
Figure 10.7. Modeling state changes in a communication diagram.Note the nested message (3.1:
«become»)
Figure 10.8 shows an alternative technique for modeling state changes. I prefer the first way as
the dotted-line arrow in the second brings to mind a dependency. People who are new to UML
often find dependencies difficult to follow.
Software Design and Architecture
4th Semester-SE
UET Taxila
Figure 10.8. Another way to model state changes in a communication diagram.
Modeling with Communication Diagram
The following elements are available in a collaboration diagram.





Object
Link
SelfLink
Stimulus
Frame
Object
In order to create Object,
Software Design and Architecture
4th Semester-SE
UET Taxila
1. Click [Toolbox] -> [Collaboration] -> [Object] button.
2. And click at the position where Object will be placed in the [main window].
3. Then quick dialog is shown. At the quick dialog, enter the object name.
4. And press [Enter] key.
Procedure for creating outgoing from object stimulus by using shortcut creation syntax
In order to create outgoing stimulus from selected object to another object,
1. Double-click from-object, or select from-object and press [Enter] key to pop up quick
dialog.
2. At the quick dialog, enter stimulus name after "->" string ("<-" string for incoming and
"<->" for outgoing with return).
Software Design and Architecture
4th Semester-SE
UET Taxila
3. Press [Enter] key and outgoing stimulus from selected object to target object is created
and placed at the last order.
Procedure for setting active object
In order to set class to active object,
1. Set assigned class's [IsActive] property to true.
2. For MyObject, change MyClass's [IsActive] property.
3. If class property is not assigned, you can't change object to active object.
Procedure for setting to multi object
In order to set object to multi object,
Software Design and Architecture
4th Semester-SE
UET Taxila
1. Set object's IsMultiInstance property to true.
2. Then the object is assigned as multi object.
Procedure for creating object from class
In order to create object from class,
1. Select class in the [model explorer].
Software Design and Architecture
4th Semester-SE
UET Taxila
2. Drag it into collaboration diagram.
3. Then the object(instance of the class) is created.
Procedure for creating class from object
If class is not assigned to object,
1. Double-click object to pop up quick dialog. Then quick dialog is opened.
2. At the quick dialog, click add class button.
3. At the [Enter element name] dialog, enter new class name.
Software Design and Architecture
4th Semester-SE
UET Taxila
4. Then new class is created and assigned to object.
If you want existing class to be assigned to object, enter the existing class name at the [Select a
model element] dialog.
Procedure for adding AttributeLink to object
There are two way to add attribute link to Object.


using object model in the main diagram or the [model explorer]
using [collection editor]
In the case of using object model,
1. Select object in the [main window] or in the [model explorer].
2. Right-click the selected object, select [Add] -> [Attribute Link] popup menu, and you
can add Attribute Link.
3. Then new attribute link is created.
In the other case,
Software Design and Architecture
4th Semester-SE
UET Taxila
1. Select [Collection Editor...] popup menu of object or click
property on properties window.
button in [Slots]
2. At slots tab of the [collection editor], you can add attribute link by using following
button.
Link
Procedure for creating link
In order to create Link,
1. Click [Toolbox] -> [Collaboration] -> [Link] button.
Software Design and Architecture
4th Semester-SE
UET Taxila
2. Drag from one Object and drop to the other Object in the [main window].
3. Between two objects, the link is created.
SelfLink
Procedure for creating self-link
In order to create self-link,
1. Click [Toolbox] -> [Collaboration] -> [SelfLink] button.
2. And click the object that self-link will connect to in the [main window].
Procedure for creating self-stimulus
In order to create self-stimulus,
1. Click [Toolbox] -> [Collaboration] -> [ForwardStimulus/ReverseStimulus] button.
Software Design and Architecture
4th Semester-SE
UET Taxila
2. And click the self-link that the stimulus will be placed in the [main window].
3. And double-click the stimulus, enter the stimulus name at the quick dialog.
Stimulus
Procedure for creating stimulus
In order to create stimulus,
1. Click [Toolbox] -> [Collaboration] -> [ForwardStimulus/ReverseStimulus] button.
2. Click the link that the stimulus will be placed in the [main window].
3. And double-click the stimulus, enter the stimulus name at the quick dialog.
4. The result is as follows.
Software Design and Architecture
4th Semester-SE
UET Taxila
Procedure for changing ActionKind of stimulus
The [ActionKind] property of stimulus should be assigned to one of five sort as following. To
change [ActionKind] property, select stimulus and select the [ActionKind] property on the
properties window.
ActionKind
CALL
SEND
Shape
RETURN
CREATE
DESTROY
Frame
Procedure for creating frame
In order to create Frame,
Software Design and Architecture
4th Semester-SE
UET Taxila
1. Click [Toolbox] -> [Collaboration] -> [Frame] button.
2. And click at the position where Frame will be placed in the [main window].
3. The result is as follows.
Diagram
Procedure for showing sequence numbers in the diagram
In order to show or hide stimulus sequence number, select the diagram in the [model explorer]
or in the [main window], and configure [ShowSequence] property of diagram to true or false.
Software Design and Architecture
4th Semester-SE
UET Taxila
Procedure for changing signature style of message in the diagram
There are four message styles. To change stimulus signature,
1. Select the diagram in the [model explorer] or in the [main window].
2. And configure [MessageSignature] property of diagram to one of the followings.
Style
Description
NONE
shows only message name
NAMEONLY
shows message name and argument name
TYPEONLY
shows message name, argument type, and return type
NAMEANDTYPE
shows message name, argument name, argument type, and return
type
Lab Task:
Software Design and Architecture
4th Semester-SE
UET Taxila
Activity 1:
Draw a communication diagram for a student taking a course from a teacher, who
is part of the faculty.
Activity 2
You want to login to your Facebook account draw a communication diagram for it.
It will involve security login, Account database, and home page objects. Show how
these objects communicate with each other.
Case Study
You are student of an engineering college and you want to but a book of .Net
Application development. This book is not available in your city so you have to buy
it from an online book shop. For this purpose you browsed a lot of online book
houses and in each book shop you searched the inventory of book house.
Finally in Caserta Book house you got a book with same name. To confirm that it
is your required book you see the content of book in Book View. Seeing the book as
it is related to your requirement you will add it to shopping cart.in Caserta book
shop you have to fill an order form to complete your order process. Draw
Communication diagram of above scenario.
Software Design and Architecture
4th Semester-SE
UET Taxila