0% found this document useful (0 votes)
104 views24 pages

CAED Lab 7 PDF

The document describes a lab manual for a course on UML sequence and communication diagrams. It provides instructions for the lab, including objectives to understand what sequence diagrams are, how to apply them, and how to model object creation and synchronization. It then explains what sequence diagrams are through examples, including how they show the sequence and timing of messages passed between objects. It also provides an example sequence diagram modeling the interaction between a car, car key, and car owner.

Uploaded by

Faiz Aalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
104 views24 pages

CAED Lab 7 PDF

The document describes a lab manual for a course on UML sequence and communication diagrams. It provides instructions for the lab, including objectives to understand what sequence diagrams are, how to apply them, and how to model object creation and synchronization. It then explains what sequence diagrams are through examples, including how they show the sequence and timing of messages passed between objects. It also provides an example sequence diagram modeling the interaction between a car, car key, and car owner.

Uploaded by

Faiz Aalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA

FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING


DEPARTMENT OF COMPUTER ENGINEERING

CAED

UML (Sequence and Communication Diagrams)

Lab Manual 7

Dated:
th th
15 October, 2018 to 19 October, 2018

Course Instructor: Engr. Noshina Shamir


Semester:
Fall 2017

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Lab Instructions
1. All Students should reach at lab on time.
2. Students should sit on the same computer during whole semester.
3. Student should make a directory by his/her name and store all his/her data in it.
4. Student could take the backup of his/her program the instructor permission.
5. Record Instructions: 1. Lab copy should be updated. 2. Lab copy should be checked on each lab.

Lab objective:
 What a sequence diagram is?
 How to apply a sequence diagram?
 How to model objects creation and synchronization?
 Where sequence diagrams fit into the UML?
Tools:
MS Visio, E-draw, Star UML
What is a Sequence Diagram?
The state diagrams zoom in on a single object. They show the changes an object goes through. The UML
enables you to expand your field of view and show how an object interacts with other objects. In this
expanded field of view, you'll include an important dimension - time. The key idea here is that
interactions among objects take place in a specified sequence, and the sequence takes time to go from
beginning to end. When you create a system, you specify the sequence, and you use the UML sequence
diagram to do it.
The sequence diagram consists of objects represented in the usual way (as named rectangles with the
name underlined), messages represented as solid-line arrows, and time represented as a vertical
progression.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Objects

The objects are laid out near the top of the diagram from left to right. They're arranged in any order
that simplifies the diagram. Extending downward from each object is a dashed line called the
object's lifeline. Along the lifeline is a narrow rectangle called an activation. The activation
represents an execution of an operation the object carries out. The length of the rectangle signifies
the activation's duration. Duration, and time in general, are represented in a rough, ordinal way. This
means that each dash in a lifeline usually doesn't stand for a specific unit of time but is intended to
give a general sense of duration.

Messages

A message that goes from one object to another goes from one object's lifeline to the other object's
lifeline. An object can also send a message to itself—that is, from its lifeline back to its own lifeline.
UML represents a message as an arrow that starts at one lifeline and ends at another.
One type of message is a call. This is a request from the object sending the message to the object
receiving the message. The request is for the receiver to carry out one of its (the receiver's)
operations. Usually, this entails the sender waiting for the receiver to carry out that operation.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Because the sender waits for the receiver (that is, "synchs up" with the receiver), this message is also
referred to as synchronous.
UML signifies this message type with a filled arrowhead at the end of a solid line. It's typically the
case that a call involves a return message from the receiver. The symbol for the return message is an
open-stick arrowhead with a dashed line.

Another kind of message is asynchronous. With this one, the sender transfers control to the receiver
and doesn't wait for the operation to complete. The symbol for this message is an open stick
arrowhead.

Synchronous and Asynchronous Message


 Synchronous message typically represents operation call - send message and suspend execution
while waiting for response. Synchronous Messages are shown with filled arrow head.
 Asynchronous message - send message and proceed immediately without waiting for return value.
Asynchronous Messages have an open arrow head.

Time

The diagram represents time in the vertical direction: Time starts at the top and progresses toward
the bottom. A message that's closer to the top occurs earlier in time than a message that's closer to
the bottom.
Thus, the sequence diagram is two-dimensional. The left-to-right dimension is the layout of the
CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa
Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
objects, and the top-to-bottom dimension shows the passage of time. The objects are laid out across
the top. Each object's lifeline is a dashed line extending downward from the object. A solid line with
an arrowhead connects one lifeline to another and represents a message from one object to another.

Example: Cars and Car Keys

You might be familiar with the kind of car key that allows you to remotely lock and unlock a
car. It also lets you open the car's trunk. If you have one of these keys, you know what happens
when you push the "lock" button. The car locks itself, and then it blinks its lights and beeps to let
you know it's finished locking its doors.

The Car processes a message from the key and causes the appropriate behavior to take place. Notice
a couple of things about this diagram. In the CarKey class, I've shown the signature of
CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa
Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
getButtonPress(). This operation works with a button name ("lock," "unlock," or "openTrunk"). The
idea is that the Car receives a message from the CarKey, processes that message, and implements
the operation corresponding to the name of the pressed button. The diagram also shows the two
signals BlinkLights and Beep. You model a signal as a class with the keyword «signal» added. The
dependency arrows between Car and each signal show that the Car sends these signals. Once again,
the UML has no symbol for send, so you add the keyword «send» to the dependency arrow.
CarOwner class shows something you haven't seen before in a class icon—the two occurrences of
the «signal» keyword. These show you that CarOwner is capable of receiving these signals. The
signals don't request the CarOwner to do anything. Because the Car (the sender) isn't making a
request when it sends those signals, it certainly isn't waiting for the CarOwner to do anything.
Hence, the communication or sequence diagram uses the asynchronous message symbol to model
signals.
Car and Car key - A Communication Diagram

Communication diagram is a part of Interaction Diagram. We can convert a Communication


diagram into Sequence diagram which is also an Interaction Diagram, and vice versa.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
Car and Car key - A Sequence Diagram
A sequence diagram provides a dynamic view. How? By showing the messages that pass from one
of these entities to another. Start by drawing three objects. One object is an instance of CarOwner,
another is an instance of CarKey, and the third is an instance of Car. Lay them out across the top of
the diagram and drop a lifeline from each one.

Next, add the arrows to model messages that go from lifeline to lifeline. The first message (the one
highest in the vertical dimension) is a request from CarOwner to CarKey. The request is for CarKey to
implement its getKeyPress() operation, registering the button the CarOwner has pressed (generically
referred to as b). The stick arrowhead indicates that CarOwner is transferring control to CarKey.
CarKey then sends a message to Car, calling on Car to implement its processKeyMessage() operation,
depending on the specified button. After it processes the message from CarKey, Car sends itself a
message to implement the operation that corresponds to the pressed button. Note the expression in
brackets. That's a guard condition. It's the UML's way of saying "if." So if the pressed button was "lock,"
the Car sends itself a request to carry out the lock() operation.
Then Car sends its two signals to CarOwner. The first message and the signals are examples of the two
usages of the stick arrowhead.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Lab Tasks:
Task 1:
Consider “The Soda Machine Model”

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
In your model of the soda machine:
The Front
 Accepts selections and cash
 Displays prompts like "Out of selection" and "Use correct change"
 Receives change from the register and makes it available to the customer
 Returns cash
 Receives a can of soda from the dispenser and makes it available to the customer
The Register
 Gets the customer's input (that is, the selection and the cash) from the front
 Updates its cash reserve
 Checks for change
The Dispenser
 Checks the availability of a selection
 Releases a can of soda
Sequence Diagram for best-case scenario of Buy-Soda use case:

Sequence Diagram for sold-out scenario of Buy-Soda use case:

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Sequence Diagram for incorrect-change scenario of Buy-Soda use case:

Sequence Diagram for incorrect-change and machine-is-out-of-change scenario


of Buy-Soda use case:

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Draw a generic sequence diagram for Buy-Soda use case which includes all
scenarios in a single sequence diagram.
Task 2:
Creating an Object
To model object creation in a sequence diagram, put «create» on the message label.

 Modify your diagram in Task 1 to create a new Transaction’s object. (Note: When a
customer buys a can of soda and insert money, and the selection is available, then a new
transaction record is created and the machine then release the soda to the front).

Destroying an Object

While we're on the subject of object creation, we should also talk about object destruction. To show
an object being destroyed, you place a large, bold X at the bottom of its lifeline. The left-hand part
of the figure below shows an object destroying itself (perhaps because a certain amount of time has
passed). The right-hand part of the figure shows that an object can instruct another object to destroy
itself. It does this by sending a message whose label is a «destroy» keyword.
CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa
Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

 Modify your diagram in to destroy newly created Transaction’s object. (Note: When a customer
receive a can of soda from the front, front then destroy the newly created transaction record or after a
certain time, the newly created record can destroy itself).

Communication Diagrams
Objective:
 What a communication diagram is?
 How to apply a communication diagram?
 How to model active objects, concurrency, and synchronization?
 Where communication diagrams fit into the UML?
Tools:
MS Visio, E-draw, Star UML
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

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
would add confusion.
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. Object diagram shows
static information and Communication diagram depicts dynamic information. Communication
diagram is a part of Interaction Diagram. We can convert a Communication diagram into
Sequence diagram (which is also an Interaction Diagram) and vice versa.
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. We represent
sequential information in a communication diagram by adding a number to the label of a message,
with the number corresponding to the message's order in the sequence. A colon separates number
from message.
Synchronous message typically represents operation call - send message and suspend execution
while waiting for response. Synchronous Messages are shown with filled arrow head.

Asynchronous message - send message and proceed immediately without waiting for return value.
Asynchronous Messages have an open arrow head.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Example:

Cars and Car Keys

You might be familiar with the kind of car key that allows you to remotely lock and unlock a
car. It also lets you open the car's trunk. If you have one of these keys, you know what happens
when you push the "lock" button. The car locks itself, and then it blinks its lights and beeps to let
you know it's finished locking its doors.

The Car processes a message from the key and causes the appropriate behavior to take place. Notice
a couple of things about this diagram. In the CarKey class, I've shown the signature of
getButtonPress(). This operation works with a button name ("lock," "unlock," or "openTrunk"). The
idea is that the Car receives a message from the CarKey, processes that message, and implements
the operation corresponding to the name of the pressed button.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
The diagram also shows the two signals BlinkLights and Beep. You model a signal as a class with
the keyword «signal» added. The dependency arrows between Car and each signal show that the Car
sends these signals. Once again, the UML has no symbol for send, so you add the keyword «send»
to the dependency arrow.

Note that the CarOwner class shows something you haven't seen before in a class icon—the two
occurrences of the «signal» keyword. These show you that CarOwner is capable of receiving these
signals. The signals don't request the CarOwner to do anything. Because the Car (the sender) isn't
making a request when it sends those signals, it certainly isn't waiting for the CarOwner to do
anything. Hence, the communication or sequence diagram uses the asynchronous message symbol to
model signals.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Changing States and Nesting Messages:

Suppose Car has an attribute, locked, whose values are either True or False. Thinking back
"Working with State Diagrams," you can imagine two states, Locked and Unlocked for Car.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

You can show a change of state in a communication diagram. To do that in this example, you show
the value of locked in the Car object. Then, you duplicate the Car object 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.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

One more point about numbering:


Sometimes, two messages come out of a decision process, and their guard conditions are mutually
exclusive. How do you number them?

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Multiple Receiving Objects in a Class:

Sometimes an object sends a message to multiple objects in the same class. A professor, for
example, asks a group of students to hand in an assignment. In the communication diagram, the
representation of the multiple objects is a stack of rectangles extending backward. You add a
bracketed condition preceded by an asterisk to indicate that the message goes to all objects.

In some cases, the order of message-sending is important. For example, a bank clerk serves each
customer in the order that he or she appears in line. You represent this with a while whose condition
implies order (such as line position = 1. . .n) along with the message and the stacked rectangles.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Active Objects:

In some interactions, a specific object controls the flow of messages. This active object can send
messages to passive objects and interact with other active objects. In a library, for instance, a
librarian takes reference requests from patrons, looks up reference information in a database, gives
information back to the patrons, assigns workers to restock books, and more. A librarian also
interacts with other librarians who are carrying out the same operations. When two or more active
objects do their work at the same time, it's called concurrency.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Synchronization:

Another circumstance you might run into is an object sending a message only after several other
(possibly nonconsecutive) messages have been sent. That is, the object must synchronize its message
with a set of other messages.
An example will clarify this for you. Suppose your objects are people in a corporation, and
they're concerned with a new product campaign. Here is a sequence of possible interactions:
1. The Senior VP of Marketing asks the VP of Sales to create a campaign for a particular product.
2. The VP of Sales creates the campaign and tells the Sales Manager to assign the campaign to a
Salesperson.
3. The Sales Manager directs a Salesperson to sell the product according to the campaign.
4. The Salesperson makes sales calls to potential customers in order of their priority.
5. After the Sales Manager has issued the directive (that is, when steps 3 is complete), a corporate
Public Relations Specialist has the local newspaper place an ad about the campaign.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

Lab Tasks:
Task 1:
Consider “The Soda Machine Model”

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
In your model of the soda machine:

The Front
 Accepts selections and cash
 Displays prompts like "Out of selection" and "Use correct change"
 Receives change from the register and makes it available to the customer
 Returns cash
 Receives a can of soda from the dispenser and makes it available to the customer
The Register
 Gets the customer's input (that is, the selection and the cash) from the front
 Updates its cash reserve
 Checks for change
The Dispenser
 Checks the availability of a selection
 Releases a can of soda

Draw a communication diagram for Buy-Soda use case. Consider Communication is among
Customer, Front, Register and Dispenser.
Task 2:
Creating an Object

To model object creation in a communication diagram, put «create» on the message label.

Modify your diagram in Task 1 to create a new Transaction’s object. (Note: When a customer buys
a can of soda and insert money, then a new transaction record is created).

Task 3:
Draw a communication diagram for registering a student for a workshop related to a particular
course.

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING

CAED Session:-2K17 Computer Lab Instructor:-Adnan Mustafa


Engineering

You might also like