Week 12 Collaboration Diagram
Week 12 Collaboration Diagram
Collaboration Analysis
Diagram CS-324
Lecture # 31,32
16,18 Nov
Rubab Jaffar
[email protected]
Today’s Outline
• Collaboration Diagram Semantics
• Collaboration Diagram Notation
• Collaboration Diagram Examples
• Collaboration Diagram Issues
SDA 2
Collaboration Diagram
Semantics
• Member of the Behavioral Group of diagrams
• Collaboration Diagrams captures dynamic
behavior of the objects in the system.
• They are very useful for visualizing the relationship
between objects collaborating to perform a
particular task.
SDA 3
Collaboration Diagram
• Represents a Collaboration and Interaction
• Collaboration set of objects and their interactions
in a specific context
• Interaction set of messages exchanged in a
collaboration to produce a desired result
• Their purpose is to:
o Model flow of control
o Illustrate coordination of object structure and control
SDA 4
What it Represents?
• Collaboration Diagrams illustrate object interactions
in a graph or network format.
SDA 5
Collaboration Diagram Elements
• There are three primary elements of a
collaboration diagram:
o Objects
o Links
o Messages
SDA 6
Collaboration Diagram
Syntax
AN ACTOR
AN OBJECT anObject:aClass
AN ASSOCIATION
A MESSAGE aMessage()
SDA 7
Notations used for
Collaboration Diagrams-Objects
• Objects rectangles containing the object signature
o object name : object Class
o object name (optional) - starts with lowercase
letter
o class name (mandatory) - starts with uppercase
letter
• Objects connected by lines ,actor can appear
SDA 8
Notations used for
Collaboration Diagrams-Objects
• Objects participating in a collaboration come in
two flavors—supplier and client
SDA 9
Transaction object acts as a Supplier to the UI (User Interface) Client object.
In turn, the Fine object is a Supplier to the Transaction Client object.
SDA 10
Notations used for
Collaboration Diagrams-Links
• The connecting lines drawn between objects are
links
• They enable you to see the relationships between
objects
• This symbolizes the ability of objects to send
messages to each other
• A single link can support one or more messages sent
between objects
SDA 11
Notations used for Collaboration Diagrams-Links
SDA 12
Notations used for Collaboration
Diagrams- Messages
• An interaction between objects is implemented by
exchanging messages.
• Messages in collaboration diagrams are shown as
arrows pointing from the Client object to the Supplier
object.
• Typically, messages represent a client invoking an
operation on a supplier object
• Message icons have one or more messages
associated with them.
• Messages are composed of message text prefixed by
a sequence number
• Time is not represented explicitly in a collaboration
diagram, and as a result the various messages are
numbered to indicate the sending order.
SDA 13
Example
• Here are the steps that occur in the use case named
‘Borrow Book’.
• The librarian enters the borrower id in the system through
UI to get the details about the number of books
borrower can have.
• The UI calls the transaction object to calculate the
amount that can be borrowed.
• Transactions objects creates and calculate the fine for
borrower id .
• Borrowers checked out media and overdue media is
also checked by transaction object and then returned
to UI to displays this information for the librarian.
• If borrower’s amount is equal to zero then UI displays the
invalid message.
SDA 14
This particular sequence, shown in Figure , documents the interaction that
occurs between business objects when determining how many items a
borrower can check out of the library.
SDA 15
Notations used for Collaboration
Diagrams-Messages
SDA 16
Iterating Messages
• Collaboration diagrams use syntax similar to
sequence diagrams to indicate that either a
message iterates (is run multiple times) or is run
conditionally
o An asterisk (*) indicates that a message runs more than
once
o Or the number of times a message is repeated can be
shown by numbers (for example, 1..5)
SDA 17
Conditional Messages
• To indicate that a message is run conditionally,
prefix the message sequence number with a
conditional [guard] clause in brackets
o [ x = true ]: [IsMediaOverdue]
SDA 18
Nested Message
• The nested message represents a procedure call or
other nested flow of control. The nested sequence is
completed before the outer level sequence
resumes. The nested message symbol is represented
by a filled solid arrowhead.
SDA 19
Flat message
• The flat message shows the progression to the next
step in a sequence. The flat message symbol is
represented by a stick arrowhead.
SDA 20
Creation and Deletion
• Unlike sequence diagrams, you don't show an
object's lifeline in a collaboration diagram.
• If you want to indicate the lifespan of an object in a
collaboration diagram, you can use create and
destroy messages to show when an object is
instantiated and destroyed.
SDA 21
Objects Changing State
• State of on object can be indicated
• Initial state is indicated with <<create>>
• If an object changes significantly during an
interaction, you can add a new instance of the
object to the diagram, draw a link between them
and add a message with the stereotype
<<become>>
SDA 22
Change State of an Object
SDA 23
Steps to Creating a Collaboration
Diagram
1. Determine the scope of the diagram- the
use case it relates to.
2. Place the objects that participate in the
collaboration on the diagram
o Remember to place the most important objects
towards the center of the diagram.
3. If a particular object has a property or
maintains a state that is important to the
collaboration, set the initial value of the
property or state.
SDA 24
Steps to Creating a
Collaboration Diagram
4. Create links between the objects
5. Create messages associated with each link
6. Add sequence numbers to each message
corresponding to the time-ordering of
messages in the collaboration
SDA 25
Collaboration Diagram
Examples
SDA 26
Elevator- Collaboration Diagram
SDA 27
Online Book Purchase
Collaboration Diagram
SDA 28
Collaboration vs Sequence
Diagram
• In reality, sequence diagrams and collaboration
diagrams show the same information, but just present
it differently
• Not used as often as sequence diagrams but are
closely related
• Sequence Diagrams are arranged according to Time.
• Collaboration Diagrams represent the structural
organization of object.
• [Both sequence and collaboration diagrams are
called interaction diagrams]
SDA 32
Collaboration vs Sequence
Diagram
• In sequence diagrams, each message icon represents
a single message.
• In collaboration diagrams, a message icon can
represent one or more messages.
o Notice between the Transaction and Fine objects - there is a single message
icon, but there are two messages (1.1.1 and 1.1.2) associated with the icon.
SDA 33
Collaboration VS
Sequence Diagram
• Collaboration diagram illustrates object interactions in
a graph or network format, in which objects can be
placed anywhere on the diagram. It demonstrates
how objects are statically connected.
• Sequence diagram illustrates interaction in a kind of
fence format, in which each new object is added to
the right. It generally shows the sequence of events
that occur.
SDA 34
Why Collaboration
Diagrams?
• Collaboration diagrams offer a better view of a
scenario than a Sequence diagram when the
modeler is trying to understand all of the effects on
a given object and are therefore good for
procedural design.
SDA 35
If-else
if (x<y)
{
object2.message1();
object3.message3();
}
else
{
object2.message2();
}
SDA 37
Collaboration diagrams –
strengths and weaknesses
• One of the greatest strengths of collaboration
diagrams is their simplicity.
• The principal weakness, however, is that although they
are good at describing behavior, they do not define it.
They typically do not show all the iteration and control
that is needed to give an computationally complete
description.
• Strengths:
- they clearly show sequence or time ordering of messages.
- the notation is rather simple
• Weaknesses:
- forced to extend to right when adding new objects, consumes a lot of space
SDA 38
Class Activity
• Consider the software that controls a very simple
cellular telephone. Such a phone has buttons for
dialing digits, and a “send” button for initiating a call. It
has “dialer” hardware and software that gathers the
digits to be dialed and emits the appropriate tones. It
has a cellular radio that deals with the connection to
the cellular network. It has a speaker, and a display.
SDA 41
Example
SDA 42
Example
SDA 43
That is all
SDA 44