Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

OOAD: Dynamic Interaction Modeling: Presenter: Dr. Ha Viet Uyen Synh

Download as pdf or txt
Download as pdf or txt
You are on page 1of 35

OOAD: Dynamic Interaction Modeling

Presenter: Dr. Ha Viet Uyen Synh.


PART #2

INTERACTION DIAGRAM
Role of Interaction Diagrams in UML
Interaction Diagram
Interaction diagrams describe exemplary how groups of
objects collaborate in some behavior.

An interaction diagram typically captures the behavior of


a user goal use case.

Interaction diagrams do not capture the complete


behavior, only typical scenarios

There are two types of interaction diagrams:


Sequence diagrams emphasize the order or
concurrency of the interactions.
Collaboration diagrams emphasize the
interacting objects
Sequence Diagram
A sequence diagram describes an interaction among a set of objects participated
in a collaboration (or scenario), arranged in a chronological order; it shows the
objects participating in the interaction by their "lifelines" and the messages that
they send to each other.
Sequence Diagram
Sequence Diagram Notations

Activation Note
Sequence Diagram Notations

Call Message Return Message

Create Message Destroy Message

Self Message Recursive Message Duration Message


Example
Control structure

Alternative Loop Parallel

Option Break Reference


Alternative
The instance shows the sequence starting at the top, with the bank
object getting the check’s amount and the account’s balance.

At this point in the sequence the alternative combination fragment


takes over. Because of the guard (balance >= amount), if the
account’s balance is greater than or equal to the amount, then the
sequence continues with the bank object sending the
addDebitTransaction and storePhotoOfCheck messages to the account
object.

However, if the balance is not greater than or equal to the amount,


then the sequence proceeds with the bank object sending the
addInsuffientFundFee and noteReturnedCheck message to the
account object and the returnCheck message to itself.

The second sequence is called when the balance is not greater than or
equal to the amount because of the \[else\] guard. In alternative
combination fragments, the \[else\] guard is not required; and if an
operand does not have an explicit guard on it, then the \[else\] guard
is to be assumed.
Option
According to the sequence diagram in Figure 9, if a student’s past due
balance equals zero, then the addStudent, getCostOfClass, and
chargeForClass messages are sent. If the student’s past due balance
does not equal zero, then the sequence skips sending any of the
messages in the option combination fragment.
Loop
Referencing another sequence
diagram
Break
Parallel
Concurrent Processes and Activations
UML offers diagram elements to show concurrent
processes explicitly within sequence and collaboration
diagrams.

Activation:
• indicates whenever a method is active,
• shows methods which are waiting for returns.

Asynchronous message:
• allows the creation of new threads or objects,
• communicates with already running threads or objects.

Deletion:
• occurs by self destruction of threads or objects,
• can be initiated by external messages.
Concurrency in Sequence Diagrams
Example:
- A bank transaction transfers $100 from bank account #123 to
#456.
• Withdraw $100 from bank account #123.
• Deposit $100 at bank account #456.

- Withdraw and deposit may be executed in parallel (concurrently).

- The transaction is only successful if both sub-transactions


(withdraw and deposit) are successful.

- Therefore a transaction coordinator checks the successful


completion of the concurrent sub-transactions.
• Each time a sub-transaction completes successfully it checks if all
other sub-transactions have been completed successfully. If this is
the case, it reports success to its client.
• If any sub-transaction fails, it cancels the other sub-transactions
and reports failure to its client.
Concurrency in Sequence Diagrams
Concurrency in Sequence Diagrams
A Successful Bank Transaction
A Failing Bank Transaction
Forms of system control
What can you say about the control flow of each of the
following systems?
- Is it centralized?
- Is it distributed?
Example
Exercise #1

What’s wrong here?


Exercise #2

A complete
SSD for the
RMO use
case Create
new order

28
Summary
Collaboration Diagrams
Dynamic behavior of objects can, in addition to
sequence diagrams, also be represented by
collaboration diagrams.

The transformation from a sequence diagram into a


collaboration diagram is a bidirectional function.

The difference between sequence diagrams and


collaboration diagrams is that collaboration diagrams
emphasize more the structure than the sequence of
interactions.

Within sequence diagrams the order of interactions is


established by vertical positioning whereas in
collaboration diagrams the sequence is given by
numbering the interactions.
Collaboration Diagrams
When to Use Interaction Diagrams
Use Interaction Diagrams
- When catching user requirements:
• Describe the behavior of several objects within a user goal
use case.
• Show collaborations among objects.
- After having described the object behavior completely with
state and activity diagrams:
• Test the state and activity diagrams against the scenarios

Do not Use Interaction Diagrams


- For precise definition of a single class behavior (use state
diagrams).
- If you want to describe the behavior across many use
cases or many threads (consider an activity diagram).
Homework #1_ An online stock broker
Write an activity diagram for the processing of a stock trade
order that has been received by an online stock broker.

The online stock broker first verifies the order against the
customer’s account, then executes it with the stock
exchange.

If the order executes successfully, the system does three


things concurrently: mails trade confirmation to the
customer, updates the online portfolio to reflect the results
of the trade, and settles the trade with the other party by
debiting the account and transferring cash or securities.

When all three concurrent threads have been completed,


the system merges control into a single thread and closes
the order. If the order execution fails, then the system
sends a failure notice to the customer and closes the order.
Homework #2
The scenario begins when the user chooses to add a new
appointment in the UI. The UI notices which part of the calendar is
active and pops up an Add Appointment window for that date and
time.

The user enters the necessary information about the


appointment's name, location, start and end times. The UI will
prevent the user from entering an appointment that has invalid
information such as an entering an appointment that has invalid
information, such as an empty name or negative duration. The
calendar records the new appointment in the user's list of
appointments. Any reminder selected by the user is added to the
list of reminders.

If the user already has an appointment at that time, the user is


shown a warning message and asked to choose an available time
or replace the previous appointment. If the user enters an
appointment with the same name and duration as an existing
group meeting the calendar asks the user whether he/she
intended to join that group meeting instead. If so, the user is
added to that group meeting's list of participants.
Any Questions?

 hvusynh@hcmiu.edu.vn

You might also like