Date post: | 17-Jan-2016 |
Category: |
Documents |
Upload: | may-allison |
View: | 212 times |
Download: | 0 times |
Collaboration diagrams
Purpose
• A collaboration diagram is an alternate way to show a scenario.
• A collaboration diagram shows the objects and relationships involved in an interaction, and the sequence of messages exchanged among the objects during the interaction.
Compared with a sequence diagram • A sequence diagram shows the objects and messages
involved in an interaction. • They convey the same information as sequence diagrams,
but they focus on object roles instead of the times that messages are sent
• Sequence diagrams show the timing of the messages, but not the relationships among the objects.
• A distinguishing feature of a Collaboration diagram is that it shows the objects and their association with other objects in the system apart from how they interact with each other. – The association between objects is not represented in a Sequence
diagram. • Within sequence diagrams the order of interactions is
established by vertical positioning whereas in collaboration diagrams the sequence is given by numbering the interactions.
Elements of a collaboration diagram
Object: The objects interacting with each other in the system. Depicted by a rectangle with the name of the object in it, preceded by a colon and underlined.
Relation/Association: A link connecting the associated objects. Qualifiers can be placed on either end of the association to depict cardinality.
Messages: An arrow pointing from the commencing object to the destination object shows the interaction between the objects. The number represents the order/sequence of this interaction.
Messages
• Unlike sequence diagrams, collaboration diagrams do not have an explicit way to denote time and instead number messages in order of execution.
• Sequence numbering can become nested using the Dewey decimal system. – For example, nested messages under the first
message are labeled 1.1, 1.2, 1.3, and so on. – The a condition for a message is usually placed in
square brackets immediately following the sequence number.
– Use a * after the sequence number to indicate a loop.
Messages
Example
• An Administrator using a Web Application to manage a user account.
• Notice how you can follow the process from object to object, according to the outline below:
1. Find User 1.1 LookUpUser
2. Update User 2.1 ValidateUser 2.2 UpdateUser
Example
As a decomposition diagram • The collaboration diagram can be a
decomposition of a class, class diagram, or part of a class diagram;
• it can be the decomposition of a use case, use case diagram, or
• part of a use case diagram.
Collaboration diagrams
• illustrate object interactions in a graph or network format.
:ClassAInstance
:ClassBInstance
1: message2()
2: message3()
message1()
Example Collaboration Diagram:makePayment
1: makePayment(cashTendered)
1.1: create(cashTendered)
: Register :Sale
:Payment
makePayment(cashTendered)
creation indicated with a"create" message
direction of message
first message
instance
first internal message
link line
parameter
How to Read the makePaymentCollaboration Diagram
1. The message makePayment is sent to an instance of Register. The sender is not identified.
2. The Register instance sends the makePayment message to a Sale instance.
3. The Sale instance creates an instance of a Payment.
: Register
:Sale
:Payment
makePayment(cashTendered)
1: makePayment(cashTendered)
1.1: create(cashTendered)
Example Sequence Diagram:makePayment
: Register : Sale
makePayment(cashTendered)
makePayment(cashTendered)
: Paymentcreate(cashTendered)
an activation box showingthe focus of control
Messages to “self” or “this”
• A message can be sent from an object to itself.
• This is illustrated by a link to itself, with messages flowing along the link.
: Register
msg1()
1: clear()
: Register
msg1()
clear()
Conditional Messages
• A conditional message is shown by following a sequence number with a conditional clause in square brackets, similar to the iteration clause.
• The message is sent only if the clause evaluates to true.
1 [ new sale ] : create(cashier): Register : Sale
makeNewSale()
conditional message, with test
: Bar: Foo
[ color = red ] calculate()message1()
Collaboration Diagram
Sequence Diagram
Mutually Exclusive Conditional Paths
1a [test1] : msg2()
:ClassA :ClassB
:ClassC
1a.1: msg3()
msg1()
:ClassD
1b [not test1] : msg4()
1b.1: msg5()
:ClassE
2: msg6()
unconditional aftereither msg2 or msg4 1a and 1b are mutually
exclusive conditional paths
: B: A
[ x < 10 ] calculate()message1()
: C
[ x > 15 ] calculate()
Collaboration Diagram
Sequence Diagram
Iteration or Looping
• Iteration is indicated by following the sequence number with a star *
• This expresses that the message is being sent repeatedly, in a loop, to the receiver.
• It is also possible to include an iteration clause indicating the recurrence values.
1 * [i:=1..N]: num := nextInt(): SimulatorrunSimulation() : Random
iteration is indicated with a * and an optionaliteration clause following the sequence number
: Simulator : Random
* [i:=1..N]: num := nextInt()
runSimulation()
Collaboration Diagram
Sequence Diagram