0% found this document useful (0 votes)
12 views58 pages

Unit-2.2 PPT Basic Collaboration Diagram

The document discusses collaboration and sequence diagrams, focusing on their roles in illustrating object interactions within applications. Collaboration diagrams emphasize the organization and messaging between objects, while sequence diagrams detail the temporal order of these interactions. Both diagrams serve to model high-level interactions and can be converted into one another, providing different perspectives on the same information.
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)
12 views58 pages

Unit-2.2 PPT Basic Collaboration Diagram

The document discusses collaboration and sequence diagrams, focusing on their roles in illustrating object interactions within applications. Collaboration diagrams emphasize the organization and messaging between objects, while sequence diagrams detail the temporal order of these interactions. Both diagrams serve to model high-level interactions and can be converted into one another, providing different perspectives on the same information.
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/ 58

Collaboration Diagrams and Sequence Diagrams

2
Diagram (review)
 Class diagrams are composed of static entities.
• Classes, packages, etc
 Interaction diagrams describe the behavior of an application.
• They are dynamic in nature.
• Thus, they are composed of dynamic entities : objects.
 We will focus on two kinds of interaction diagrams :
• Collaboration Diagrams
• Sequence Diagrams

3
Collaboration Diagram
 A collaboration diagram emphasizes the organization of the objects that participate
in an interaction.
 The collaboration diagram illustrates messages being sent between classes and
objects (instances).
 Collaboration diagrams express both the context of a group of objects (through
objects and links) and the interaction between these objects (by representing
message broadcasts)
 A collaboration diagram is a network model of the messages between interacting
objects and classes.

4
Purpose of the Collaboration Diagram

 They are very useful for visualizing the relationship between objects collaborating
to perform a particular task
 They provide a good view –static - view of interaction between objects which may
be difficult to see at the class level
 There is a UML convention for numbering the messages to show the sequence in
which they occur.

5
Collaboration Diagram Elements
 There are three primary elements of a collaboration diagram:
• Objects
• Links (Associations)
• Messages

6
Steps to create Collaboration Diagram
1. Identify behavior whose realization and implementation is specified
2. Identify the structural elements (class roles, objects, subsystems) necessary to
carry out the functionality of the collaboration
3. Model structural relationships between those elements to produce a diagram
showing the context of the interaction
4. Consider the alternative scenarios that may be required
● Draw instance level collaboration diagrams, if required.
● Optionally draw a specification level collaboration diagram to summarize the
alternative scenarios in the instance level sequence diagrams

7
Collaboration Diagram Example-1

8
Collaboration Diagram Syntax

AN ACTOR

AN OBJECT anObject:aClass

AN ASSOCIATION

A MESSAGE
aMessage()
9
Collaboration Diagram Example-2

10
Objects
 Objects-rectangles containing the object signature:
• object name : object Class
• object name (optional) - starts with lowercase letter
• class name (mandatory) - starts with uppercase letter
 Objects connected by lines-actor can appear
 Objects participating in a collaboration come in two flavors—supplier and client
 Supplier objects are the objects that supply the method that is being called, and
therefore receive the message
 Client objects call methods on supplier objects, and therefore send messages

11
Collaboration Diagram Example-3

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.
12
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

13
Collaboration Diagram Example-4

The visual representation of a link is a straight line between two objects. If an object
sends messages to itself, the link carrying these messages is represented as a loop icon.
This loop can be seen on both the UI object and the Transaction object.
14
Messages
 An interaction is implemented by a group of objects that collaborate 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

15
Flow by Number

1. Enter Borrower ID
1.1 CalcAmtCanBorrow
1.1.1 <<create>>
1.1.2 CalcBorrowerFines
1.1.3 GetBorrowersCheckedOutMedia
1.1.4 IsMediaOverdue
1.1.5 Amt Can Borrow
1.2 Display Invalid User Msg

16
Message Flow Notation

17
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
• An asterisk (*) indicates that a message runs more than once
• Or the number of times a message is repeated can be shown by numbers (for
example, 1..5)

18
Iterating Messages
 Suppose we have an object DrawArea which has a shapes array of Polygons
(Triangles, Rectangles and Squares) that belong to its area.
 We want to repeatedly send the message show() to all the constituent objects
(Polygons) of the aggregate object (DrawArea).
 Iterator Pattern (a design pattern) can be used as a traversal method.
 Notice the aggregate connector.
 show() message is called many times (the *)
 DrawArea may have 0 or more Polygons in its array named shapes.
 Target object is unnamed and double boxed to show multiplicity.

19
Conditional Messages
 To indicate that a message is run conditionally, prefix the message sequence
number with a conditional [guard] clause in brackets [ x = true ]:
[IsMediaOverdue]
 This indicates that the message is sent only if the condition is met

20
Polymorphism
 Polymorphism is a problem in object interaction.
 Suppose we want to send the message show() to a Shape object.
• That could be an instance of Triangle, Rectangle or Square at run-time.
• How do we depict this in a collaboration diagram?
 Usually, we are certain that o1 sends a message to o2
 Also, suppose that Triangle, Rectangle and Square are subclasses of Shape.
 Make the target object's class the lowest class in the inheritance hierarchy that is a
superclass of all the classes to which the target object may belong to.
 Put the superclass name in parenthesis to show that it will be evaluated at run-time.
 This is a form of substitutability.

21
Referring to Self
 When an object refers to self, it is referring to its own object handle.
• In Python, we also use the keyword self
• In Java, C++ and PHP, we use the keyword this
• In Visual Basic, we use the keyword me
 This is useful to
• Pass the target object a reference to the sender object (for callbacks)
• Send a message to itself

22
Passing a reference to self
 In message, just add self as an argument.

23
Sending a message to self
 There are two ways to depict this.

24
Callback
• The more formal description of callback is executable code that is passed as an
argument to other code.
• However, the term callback is also used when a reference is passed to achieve the
same thing.
• Callbacks are often used in asynchronous messaging.

25
Sequence Diagrams
 Sequence diagrams offer an alternate way of expressing the exchange of messages
that occur between objects in an object-based system.
 The notation for objects and collections is the same as used in collaboration
diagrams. Time ordering is from top to bottom.
 UML Sequence Diagrams are interaction diagrams that detail how operations are
carried out. They capture the interaction between objects in the context of a
collaboration.
 Sequence Diagrams are time focus and they show the order of the interaction
visually by using the vertical axis of the diagram to represent time what messages
are sent and when.

26
Sequence Diagrams
• Sequence diagrams illustrate the sequence of actions that occur in a system.
• They are composed of 2 elements
Object
Messages

27
Collaboration vs Sequence Diagram
 In reality, sequence diagrams and collaboration diagrams show the same
information, but just present it differently
 Both diagrams are illustrate interaction.
• Sequence is used to illustrate temporal interactions.
• Collaboration is better suited to display the association between the
objects.
 Given enough information, a sequence diagram can be converted into a
collaboration diagrams (and vice-versa).

28
Purpose of Sequence Diagram
❏ Model high-level interaction between active objects in a system

❏ Model the interaction between object instances within a collaboration that realizes

a use case

❏ Model the interaction between objects within a collaboration that realizes an

operation

❏ Either model generic interactions (showing all possible paths through the

interaction) or specific instances of a interaction (showing just one path through

the interaction).
29
Creating Sequence Diagrams
 Automated tools convert collaboration diagrams to sequence diagrams and vice
versa.
 Manual conversion involves using the sequence numbers in the collaboration
diagrams to place the messages in the sequence diagram in order from top to
bottom.

30
Sequence Diagram Example: Hotel System

31
Sequence Diagram : Notations
1 Actor

2 Lifeline

3 Activations

4 Call Message

32
Sequence Diagram : Notations

5 Return Message

6 Self Message

7 Create Message

33
Sequence Diagram : Notations

8 Destroy Message

9 Duration Message

10 Note

34
Example:
Food Order System

35
Example2:

Order System(offline)

36
UML: Object Interaction Diagrams
(revision)
The Collaboration Diagram

land(...)
anAircraft: Aircraft leftFlap: Flap

setAngle (landingAngle:
Angle,
out landingAngleOK:
Boolean)
The Collaboration Diagram: Depicting a Message

anAircraft: Aircraft.land(...) leftFlap: Flap

setAngle (landingAngle:
Angle,
out landingAngleOK:
Boolean)
The Collaboration Diagram: Depicting a Message

1: transferFunds(...) 2: depositFunds(...)

fromAccount: toAccount: BankAccount


BankAccount
The Collaboration Diagram: Depicting a Message

setLastWithdrawalTime
makeWithdrawal(...) (lwTime)

custAccount: Account cust: Customer


The Collaboration Diagram: Depicting a Message

makeWithdrawal(...) lastWithdrawalTime

custAccount: Account cust: Customer


The Collaboration Diagram: Polymorphism in the
Collaboration Diagram

scale(factor: PositiveReal)

icon: (Polygon)
The Collaboration Diagram: Iterated Messages

*:scale(factor: PositiveReal)
1 0..*
curDesktop: Desktop :(Polygon)
icons
The Collaboration Diagram: Use of Self in Messages

message1 (self: Class1,...)


senderObject: Class1 targetObject: Class2
The Collaboration Diagram: Use of Self in Messages

message2 (...)
senderObject: Class1 self: Class1
The Collaboration Diagram: Use of Self in Messages

message2 (...)
senderObject:
Class1
<< self >>
The Sequence Diagram
DESCRIPTION of: Transfer.makeTransfer: Boolean

create a new transfer transaction begin transaction


establish fromAccount owner establish toAccount owner

if the two owners are the same customer who also has good customer standing
then fromAccount.withdrawFunds(amt, out withDrawalOK)
else transferXaction.rollback;
return false; endif

If withDrawalOK,
then toAccount.depositFunds(amt, out depositOK)
else transferXaction.rollback;
return false;
endif

If depositOK,
then transferxaction.commit;
return true;
else transferXaction.rollback;
return false;
endif
The Sequence Diagram

:Transfer fromAccount toAccount accountOwner transferXaction


:BankAccount :BankAccount :Customer :TM

new

begin
owner

owner

standing
rollback
withdrawFunds(amt, out
withdrawalOK) permittedMinBalance time
depositFunds(amt, out
depositOK)
rollback

commit

rollback
The operation:
Depicting an Asynchronous Message

asynMessage1 (inputArg)

senderObject: Class1 targetObject: Class2


Depicting an Asynchronous Message
entryManager personelLog door doorSign: doorPlayer:
:EntryManager :Log :SecureDoor IlluminatedSign MusicPlayer

permitEntry

holdOpen(doorDuration) operate(playerDuration)

operate
(signDuration)

time
recordEntry
(personID, doorID,
actualTime)
The Callback Mechanism

registerForEventType1
(self, furtherDetails)

subscrobj: Class1 listenobj: Class2

eventType1Occured
(eventDetails)
The Callback Mechanism

userSession: emailListener: EmailRcvdWin:


Session EMailListener WinAppEmailRcvd

registerNewEMailEvent
(urgencyThresh)

newEMailReceived
(highestUrgency)

time
open (time, highestUrgency)
The Callback Mechanism
userSession: connectedPort:
Session Port

establishComm (self, ...)

commEstablished
(serverID, commOK,...)

time
Asynchronous Messages with Priority

transmitMsg(eMailMsg)
{priority = 3}

senderObject: SomeClass eMailPort: Port


Depicting a Broadcast(Nontargeted) Message

*: load( )
<< broadcast >>

:StartUpSequencer : (Object)
Depicting a Broadcast(Nontargeted) Message

*: displayCurrentReading ( )

<<broadcast>>
:DashboardMonitor : (Instrument)
Depicting a Broadcast(Nontargeted) Message
*: displayCurrentReading ( )

0..*
: (Instrument)
:DashboardMonitor instruments
Thank
You

59

You might also like