1
Software Design
Lecture : 25
2
Object Creation
• An object may create another object via a
<<create>> message.
Preferred
:A
:B
<<create>>
Constructor
:A
<<create>>
:B
3
Object Creation: Order Entry Example
Order
1
*
OrderLine
*
1
CatalogEntry
quantity: integer
cost: float
: Order
: Client
add(qty,part)
<<Creates>>
Object
creation
: CatalogEntry
: OrderLine
getCost()
return cost
5
Object Destruction
An object may destroy another object via a <<destroy>>
message.
An object may destroy itself.
Avoid
modeling
object
destruction
unless
management is critical.
:A
:B
<<destroy>>
memory
Object Destruction: Order Entry Example
: Order
: Client
remove(line)
: OrderLine
<<destroy>>
X
Object
deletion
7
Guards in Sequence Diagram
When modeling object interactions, there will be times when a
condition must be met for a message to be sent to the object.
Guards behaves likes if statements in the sequence diagram.
They are used to control the flow
We place the guard (bars) element above the message line being
guarded and in front of the message name
8
Student Registration in a class
9
Another Example of Guards
Conditional Message: Sequence Diagram
: Client
: Order
add(qty,part)
: CatalogEntry
getStockLevel(part)
return s
: OrderLine
[s>=qty] OrderLine(qty,part)
getCost()
return cost
11
Combined Fragment
Combined fragment is an interaction fragment which defines a
combination (expression) of interaction fragments.
A combined fragment is defined by an interaction operator and
corresponding interaction operands
For every option there will be corresponding action
12
ALT (UML 2.0) in Sequence Diagram
Alt keyword represents alternatives to designate a mutually
exclusive choice between two or more message sequences.
Alternatives are used to simulate “if then else” situation as it occur
in the programming languages.
Guards are used to simulate Alternatives in Sequence diagram
13
Scenario
i.
The user will submit the cheque for withdraw.
ii.
Bank will check the amount of cheque to be withdrawn.
iii. Bank will check the amount available in the account.
iv. If balance >amount to be withdrawn then debit transaction is
performed and photo of cheque is stored
v.
Otherwise the cheque will be returned with message of
insufficient fund.
14
15
Option Combination Fragment
• The option combination fragment is used to model a sequence that,
given a certain condition, will occur; otherwise, the sequence does
not occur.
• An option is used to model a simple "if then" statement without
“else”
16
17
Recurrence (Loop) in Sequence
Diagram
At time repetitions is required to control the flow of the programs.
Recurrence are like loops in the programming language.
Different Versions of UML represents Recurrence differently, we are
using UML 2
18
19