What is Collaboration? • In object-oriented systems:

Transcription

What is Collaboration? • In object-oriented systems:
What is Collaboration?
• In object-oriented systems:
– individual objects are responsible for only a bit of
overall functionality
– useful high-level behaviour (use cases) realized by
objects working together
– objects interact by sending messages to each other
• Collaboration is: “working together for the
purpose of providing some useful behaviour”
– documented by collaboration diagrams
BK - Spring 2006
ATM Case Study:
Withdrawal Use-Case Realization
Withdraw
Cash
ATMCustomer
Withdraw Cash:
The ATM customer selects the withdrawal menu, which is
displayed by the system. The card holder selects an
amount of cash. The system debits the user’s account,
returns the user’s card and issues the requested money.
BK - Spring 2006
ATM Case Study:
Identifying Collaborating Classes
The dashed line indicates
that this class participates in
the collaboration
Collaboration
icon
Withdraw
cash
ATMUI
CardHolder
BK - Spring 2006
Debit
Account
CashDispenser
UML Collaboration Diagrams
• Collaboration diagrams involve:
– Objects: instances of classes
– Links: instances of associations
– Actors: things/people interacting with the system
• A collaboration will also usually show:
– Interactions: the sequence of messages passing between objects
BK - Spring 2006
UML Notation for Objects
An object
named
user391
An anonymous
object of class
CardHolder
user391
:CardHolder
user391:CardHolder
An object named
user391 of class
CardHolder
BK - Spring 2006
Objects are notated
rather like classes,
but attributes and
operations are
omitted
UML Notation for Links
Links drawn as for
associations.
Links may have
multiplicities
:Account
1
0..*
:Debit
user391
Links are instances of
associations in the class
model
Links represent message
passing between
collaborating objects
BK - Spring 2006
ATM Case Study:
Classes Involved in the Use Case
ATMUI
CashDispenser
CardHolder
Account
Debit
BK - Spring 2006
Portion of the class
model involved in
realizing the
Withdraw Cash use
case.
ATM Case Study:
Withdrawal Collaboration Diagram
:ATMUI
:CardHolder
:ATMCustomer
Tentative collaboration
diagram for Withdraw Cash
use.
Note the structural similarity
to the class model shown
previously.
BK - Spring 2006
:CashDispenser
:Account
:Debit
Collaboration and Interaction
• Individual objects have local responsibilities:
– For data
– For behaviour
• Objects interact to achieve global behaviours:
– Use case realization
• Collaboration diagrams show interaction through:
– Structural relationship: objects and links
– Interaction: messages flowing along links
BK - Spring 2006
UML Notation for Interactions
Message number
Message name
7: get balance()
:CardHolder
Messages are sent between
objects along the links.
BK - Spring 2006
:Account
Message flow has
direction of arrow
ATM Case Study:
Collaboration with Interaction
1:select withdrawal menu
2:select amount
3:withdraw sum
:ATMUI
:ATMCustomer
Collaboration diagram
with interactions
realizing the Withdraw
Cash use case
:CardHolder
6:dispense sum
:CashDispenser
4:debit
account
:Account
5:add
debit
:Debit
BK - Spring 2006
Summary
• Individual objects are responsible for small pieces of
behaviour
• High-level functionality is achieved through object
collaboration
• UML Collaboration Diagrams show:
– Participating objects and links between objects
– Interactions (messages sent between objects).
• Stereotypes provide a mechanism for distinguishing
between different sorts of object.
BK - Spring 2006