Professional Documents
Culture Documents
Bab 10
Bab 10
Object-Oriented Technology
From Diagram to Code with Visual Paradigm for UML
1
References
Chapter 4, Object-Oriented Technology:
From diagram to code with Visual
Paradigm for UML
Chapters 15, 18, 21, The UML User
Guide
2
What You Will Learn
Model message flows using sequence
diagrams.
Model message flows using the collaboration
diagrams.
Model lifetime behaviors of an object using
statechart diagrams.
Model performance of actions of a procedure
or an activity using activity diagrams.
3
Scenario Modeling
Techniques – Interaction
Diagram
Scenario modeling describes how the objects
in a system interact with each other in a
scenario.
A scenario is a sequence of events that
occurs during one particular execution path
within a use case of a system.
Each event involves the interaction of objects
passing messages between them.
4
Scenario Modeling
Techniques – Interaction
Diagram (cont’d)
An interaction diagram can be used to model the
collaborating objects in scenarios, showing the objects
involved in the scenario and the messages sent and
received by them.
These objects may be external or internal to the system.
The messages represent the invocation of operations of
the receiving objects.
Two kinds of interaction diagrams: sequence diagrams
and collaboration diagrams.
Sequence diagrams focus on the time sequencing of
messages.
Collaboration diagrams focus on the structural
organization of the links between collaborating objects.
5
Common UML Interaction
Diagram Notation
Object Symbol
Naming Format Notation
An object of an unspecified
class.
An unnamed object of a
specified class.
6
Object Stereotype
Object Description Graphical Notations
Category
7
Object Stereotype
(cont’d)
Object Description Graphical Notations
Category
8
Messages
Message Description Notation
9
Messages (cont’d)
Message Description Notation
10
Sequence Diagrams
An interaction diagram models the behavior of a group of
objects that work together to achieve a user goal.
A sequence diagram helps us identify a set of collaborating
objects involved in a scenario of a use case.
A sequence diagram has two dimensions: the vertical
dimension and the horizontal dimension, respectively
representing the passage of time and the objects involved in
the interaction.
Object icons are placed horizontally at the top of the sequence
diagram, and messages are passed between them.
11
Sequence Diagrams
(cont’d)
12
Life Line & Activation
13
Creation & Destruction
Object Object
Creation Destruction
14
Branching
Conditional
Message
Transmission
15
Message that Takes
Time
Message Transmission that Takes Time
16
Iteration
Iteration
17
Alternate Message
Reception
Alternate
Message
Reception
18
Recursion
Recursion
19
Example
Creatio
n
Life line
Deletio
n
20
Example
Life iteratio
line n
Activati
on
21
Example
Life line
collecti
ve
iteratio
n
22
Example
Concurre
nt Branch
23
Collaboration Diagrams
Collaboration diagrams provide another way to model a
scenario.
Shows the roles of objects and associations of objects in an
instance of collaboration.
Focus on structures of the objects rather than temporal
sequence of operations.
In a collaboration diagram, each object is represented by an
object icon, and links are used to indicate communication paths
on which messages are transmitted.
Collaboration diagram = object diagram + messages between
objects.
Messages are presented in the same way as those in a
sequence diagram; in fact, sequence diagrams and collaboration
diagrams are semantically equivalent.
24
Collaboration Diagrams
(cont’d)
25
Example – Telephone
System
26
Example – Message with
Duration
27
Example – An Automatic
Teller Machine (ATM)
The ATM prompts the user to insert a card.
The user inserts an ATM card.
The ATM prompts the user to input the PIN.
The user enters the PIN.
The ATM asks the bank consortium to verify the ATM card number and
PIN.
The bank consortium verifies the ATM card number and PIN with bank.
The bank notifies the bank consortium that the PIN is correct.
The bank consortium notifies the ATM the PIN is correct.
The ATM prompts the user to select a service.
The user selects the withdraw cash service.
The ATM prompts the user to enter the amount to withdraw.
28
Example 1 – An Automatic
Teller Machine (cont’d)
The user enters the amount to withdraw.
The ATM asks the bank consortium to process the request. The bank
consortium forwards the request to bank.
The bank confirms the successful execution of the request to the bank
consortium which in turn notifies the ATM that the request has been
approved.
The ATM displays the successful transaction screen, ejects card and
then dispenses cash requested.
The ATM shows the main menu to the user for selecting the next
service.
29
Example – An Automatic
Teller Machine (cont’d)
30
Example – An Automatic
Teller Machine (cont’d)
31
Example – An Automatic
Teller Machine (cont’d)
32
Example - A Soft Drink
Vending Machine
33
Example - A Soft Drink
Vending Machine (cont’d)
34
Dynamic Modeling
Techniques Using
Statechart Diagrams
The behavior of an entity is not only a direct
consequence of its inputs, but it also depends on its
preceding state.
The past history of an entity can best be modeled by
a finite statechart diagram traditionally named
“automata”.
Statechart diagrams (or sometimes referred to as
state diagrams) show the different states of an
entity.
Statechart diagrams can also show how an entity
responds to various events by changing from one
state to another.
35
What Is a State?
According to Rumbaugh et al. “A state is an
abstraction of the attribute values and links of an
object. Sets of values are grouped together into a
state according to properties that affect the gross
behavior of the object.”
For example, consider you have $100,000 in a
bank account. The behavior of the withdraw
function would be:
balance := balance – withdrawAmount; provided that the
balance after the withdrawal is not less than $0;
However, if the account balance becomes negative after
a withdrawal, the behavior of the withdraw function
would be quite different.
36
What Is a State?(cont’d)
There are several characteristics of states:
A state occupies an interval of time.
A state is often associated with an abstraction of
attribute values of an entity satisfying some condition(s).
An entity changes its state not only as a direct
consequence of the current input, but it is also
dependent on some past history of its inputs.
37
UML Notation
38
UML Notation (cont’d)
Action or activity Description
39
UML Notation (cont’d)
Initial state
Final state
State
History state
Junction state
Concurrent composite state
Transition
40
Transition
A transition from one state to another
takes place instantaneously in response
to some external events or internal
stimuli.
41
Transition (cont’d)
A transition is fired when the following
conditions are satisfied:
The entity is in the state of the source state.
An event specified in the label occurs.
The guard condition specified in the label is
evaluated to be true.
When a transition is fired, the actions
associated with it are executed.
42
Composite State
43
Composite State (cont’d)
44