Collaboration

Interaction Diagrams - Chapter 15
Describe/illustrate sequence of message exchanges
among objects that are working together to achieve some
functionality required in the system
•used to illustrate the design required to achieve the
purpose
Types
•Collaboration diagram
•Sequence diagram
Sept 2003
91.3913
Ron McFadyen
Sample Collaboration Diagram
• Suppose an event such as a light turning red occurs, and the
traffic light must send a message to the camera letting it
know that a red light occurred.
changeToRed()
PortageMain: trafficLight
1:changeToRed()
pm: camera
1.1:takePhoto()
Sept 2003
91.3913
Ron McFadyen
Sample Sequence Diagram
• Suppose an event such as a light turning red occurs, and the
traffic light must send a message to the camera letting it
know that a red light occurred.
PortageMain: trafficLight
pm: camera
changeToRed()
changeToRed()
takePhoto()
Sept 2003
91.3913
Ron McFadyen
Interaction Diagrams
Messages
•asynchronous or synchronous
•components
•numbered (collaboration diagram)
•guard
•name
•parameter list
•name is mandatory ... others as required
Sept 2003
91.3913
Ron McFadyen
Messaging
• Synchronous messages
•asynchronous messages
•return messages
• We will assume (at first) that all messages are synchronous:
• if object A sends a message to object B then A is
suspended
• object B gains control, and B begins to compute
• object A waits until B responds (i.e. B sends a message
back to A)
•When an asynchronous message is sent from A to B, A does
not pause and wait for B to finish … results in multiple
threads of control.
Sept 2003
91.3913
Ron McFadyen
Collaboration Diagram
•Objects are represented similarly to classes in a class
model … relationships are indicated clearly
•Objects may be named or unnamed
123543:Student
:Student
•Timing is understood by the numbering scheme. We
use a nested decimal numbering to indicate the order in
which messages are sent
•Many messages may be sent across one link
Sept 2003
91.3913
Ron McFadyen
Figure 15.3 Collaboration diagram for makePayment
Messages numbered 1.1, 1.2, … are sent in response to receipt
of message numbered 1. Return messages are often left out
Sept 2003
91.3913
Ron McFadyen
Figure 15.7 Messages
Many messages may be sent across one link
Messages numbered 1, 2, 3 are sent in response to receipt of
message msg1; message 3.1 is sent in response to message 3
Sept 2003
91.3913
Ron McFadyen
Figure 15.8 Message to ‘this’
A message sent from an object to itself (i.e. invoking one of its
own methods) is indicated by a reflexive link, but this does not
imply a reflexive association
Sept 2003
91.3913
Ron McFadyen
Figure 15.9 Instance creation
We will use a create message to indicate that an object is being
instantiated
Sept 2003
91.3913
Ron McFadyen
Figure 15.10 Sequence Numbering
•The initial message triggering the collaboration is
unnumbered.
•All messages sent as the result of an object receiving a
message numbered X, are prefixed with “X.”
Sept 2003
91.3913
Ron McFadyen
We need a
numbering
scheme to
know the
order of
messages
Figure 15.11 Complex numbering
Sept 2003
91.3913
Ron McFadyen
Figure 15.12 Conditional Message
A guard (enclosed in square braces []) indicates a condition
that must be true for the message to be sent
Sept 2003
91.3913
Ron McFadyen
Figure 15.13 Mutually exclusive messages
a, b, etc are used as suffixes to indicate mutually exclusive
messages. A guard would accompany these
Sept 2003
91.3913
Ron McFadyen
Figure 15.14 Iteration
Sept 2003
91.3913
Ron McFadyen
Figure 15.15 Iteration over a multiobject
A multi-object represents a collection of objects.
E.g. the SalesLineItems for a Sale;
E.g. the ProductSpecifications for a ProductCatalog
Sept 2003
91.3913
Ron McFadyen
Figure 15.16 Messages to a class itself, not an object
A message may be sent to the class, and not to a specific object.
Sept 2003
91.3913
Ron McFadyen