Bài Giảng Phân tích thiết kế hướng đối tượng (phần 5) - Pdf 16

Use case realization
Use case realization
Lecture 5
Lecture 5
Hoa Sen University 1
Agenda
Agenda

Notations

Dependency

Interaction and Class diagrams
Hoa Sen University 2
Interaction diagrams
Interaction diagrams

Generalization of two more specialized UML diagram types

Sequence diagrams

Communication diagrams

Illustrate how objects collaborate via messages and methods
Hoa Sen University 3
Sequence vs. Communication diagram
Sequence vs. Communication diagram

Sequence diagrams
illustrate
interactions in a

ArrayList<Sale>
:Sale s1 : Sale
lifeline box representing an
instance of an ArrayList class,
parameterized (templatized) to
hold Sale objects
lifeline box representing an
unnamed instance of class Sale
lifeline box representing a
named instance
sales[ i ] : Sale
lifeline box representing
one instance of class Sale,
selected from the sales
ArrayList <Sale> collection
x : List
«metaclass»
Font
lifeline box representing the class
Font, or more precisely, that Font is
an instance of class Class – an
instance of a metaclass
related
example
List is an interface
in UML 1.x we could not use an
interface here, but in UML 2, this (or
an abstract class) is legal
Sequence diagram notation
Sequence diagram notation

control
Sequence diagram notation
Sequence diagram notation

Illustrating reply or
returns

Using the message syntax
returnVar = message(parameter).

Using a reply message line

Message to “self” or “this”
public class Register{
public void doX(){

clear();

}
public void clear(){
}
}
Hoa Sen University 7
: Register : Sale
d1 = getDate
getDate
doX
aDate
: Register
doX

create(cashTendered)

the «destroy» stereotyped
message, with the large
X and short lifeline
indicates explicit object
destruction
«destroy»
X
Sequence diagram notation
Sequence diagram notation

Diagram frames in UML sequence diagrams

Support conditional and looping construct
Hoa Sen University 9
enterItem(itemID, quantity)
: B
endSale
a UML loop
frame, with a
boolean guard
expression
description, total
makeNewSale
[ more items ]
loop
: A
Sequence diagram notation
Sequence diagram notation

Hoa Sen University 11
calculate
: Bar
yy
xx
[ color = red ]
opt
: Foo
[ color = red ] calculate
: Bar
yy
xx
: Foo

Mutually exclusive
conditional messages
public class A{
B b = new B();
C c = new C();
public void doX(){

if (x < 10)
b.calculate();
else
c.calculate();
}
}
Hoa Sen University 12
: B
: A

it is placed over the lifeline to which it applies
i++
Sequence diagram notation
Sequence diagram notation
public class Sale{
private List<salesLineItem> lineItems = new ArrayList<salesLineItem>();
public Money getTotal(){
Money total = new Money();
Money subtotal = null;
for (SalesLineItem lineItem: lineItems){
subtotal = lineItem.getSubtotal();
total.add(subtotal);
}
}
}
Hoa Sen University 14
st = getSubtotal
lineItems[i] :
SalesLineItem
t = getTotal
loop
: Sale
Sequence diagram notation
Sequence diagram notation

Nesting frames
Hoa Sen University 15
calculate
: Bar
xx

: A : B : C
doB
sd AuthenticateUser
ref
AuthenticateUser
authenticate(id)
doX
doM1
: B : C
authenticate(id)
doM2
ref
DoFoo
sd DoFoo
doX
: B : C
doY
doZ
Sequence diagram notation
Sequence diagram notation

Messages to classes to invoke static
methods
public class Foo{
public void doX(){
Locale[] locales = Calendar.getAvailableLocales();

}
}
Hoa Sen University 18

authorize() {abstract}

CreditPayment
authorize()

DebitPayment
authorize()

Payment is an abstract
superclass, with concrete
subclasses that implement the
polymorphic authorize operation
separate diagrams for each polymorphic concrete case
Sequence diagram notation
Sequence diagram notation

Asynchronous and synchronous calls

Call does not wait for a response

Asynchronous calls are used in multi-thread
application

Show as a stick arrow message

It is common for modeler to use stick arrow to
represent synchronous message

Do not assume the shape of the arrow is correct
Hoa Sen University 20

2: foo
2.1: bar
: Register :Sale
link line
1: msg2
2: msg3
3: msg4
3.1: msg5
: Register :Sale
all messages flow on the same link
msg1
Collaboration diagram notation (cont)
Collaboration diagram notation (cont)

Message to “self”
or “this”

Creation of
instances

Use a message named
create for this purpose

Create message
may have
parameters

Indicates a constructor
call with parameters in
Java

1: msg2
: C
1.1: msg3
2.1: msg5
2: msg4
: D
2.2: msg6
first second
fourth
sixth
fifth
third


Nhờ tải bản gốc

Tài liệu, ebook tham khảo khác

Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status