collaboration diagrams. purpose a collaboration diagram is an alternate way to show a scenario. a...

17
Collaboration diagrams

Upload: may-allison

Post on 17-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

Collaboration diagrams

Page 2: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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.

Page 3: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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.

Page 4: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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.

Page 5: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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.

Page 6: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

Messages

Page 7: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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

Page 8: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

Example

Page 9: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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.

Page 10: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

Collaboration diagrams

• illustrate object interactions in a graph or network format.

:ClassAInstance

:ClassBInstance

1: message2()

2: message3()

message1()

Page 11: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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

Page 12: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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)

Page 13: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

Example Sequence Diagram:makePayment

: Register : Sale

makePayment(cashTendered)

makePayment(cashTendered)

: Paymentcreate(cashTendered)

an activation box showingthe focus of control

Page 14: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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()

Page 15: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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

Page 16: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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

Page 17: Collaboration diagrams. Purpose A collaboration diagram is an alternate way to show a scenario. A collaboration diagram shows the objects and relationships

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