slide1 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
动态模型与静态模型 PowerPoint Presentation
Download Presentation
动态模型与静态模型

Loading in 2 Seconds...

play fullscreen
1 / 36

动态模型与静态模型 - PowerPoint PPT Presentation


  • 131 Views
  • Uploaded on

动态模型与静态模型. UML 交互图. UML 交互图. OO 设计的原则比画图更重要 交互图包括:顺序图和协作图. lifeline box representing the class. Font. ,. or more precisely. ,. that. Font. is. lifeline box representing a. lifeline box representing an. an instance of class. Class. –. an. named instance.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about '动态模型与静态模型' - benito


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
slide4
UML交互图
  • OO设计的原则比画图更重要
  • 交互图包括:顺序图和协作图

4

slide5

lifeline box representing the class

Font

,

or more precisely

,

that

Font

is

lifeline box representing a

lifeline box representing an

an instance of class

Class

an

named instance

unnamed instance of class

Sale

instance of a metaclass

«metaclass»

:

Sale

s

1

:

Sale

Font

List

is an interface

lifeline box representing an

lifeline box representing

instance of an

ArrayList

class

,

one instance of class

Sale

,

in UML

1

.

x we could not use an

parameterized

(

templatized

)

to

selected from the

sales

interface here

,

but in UML

2

,

this

(

or

hold

Sale

objects

ArrayList

<

Sale

>

collection

an abstract class

)

is legal

sales

:

x

:

List

sales

[

i

] :

Sale

ArrayList

<

Sale

>

related

example

常用交互图的表示法(续)
  • 生命线框图

5

slide6
常用交互图的表示法(续)
  • 消息表达式的基本语法

return = message(parameter : parameterType) : returnType

6

slide7

1

:

Register

:

Store

the ‘

1

’ implies this is a

Singleton

,

and accessed

via the Singleton pattern

doX

doA

常用交互图的表示法(续)
  • 单实例类对象
    • Singleton模式

7

slide8

:

Register

:

Sale

doX

doA

doB

创始消息

a

whose sender will not

be specified

doC

doD

execution specification

bar indicates focus of

control

sychronous

typical

message

shown with a filled

-

arrow line

顺序图的基本表示
  • 生命线、消息和活动条

8

slide9
顺序图的基本表示(续)
  • 表示应答或返回

9

slide10
顺序图的基本表示(续)
  • 发送给自身的消息

10

slide14

lineItems

[

i

]

:

:

Sale

This lifeline box represents one

SalesLineItem

instance from a collection of many

t

=

getTotal

SalesLineItem

objects

.

lineItems

[

i

]

is the expression to

select one element from the

loop

[

i

<

lineItems

.

size

]

collection of many

st

=

getSubtotal

SalesLineItems

;

the ‘i” value

refers to the same “i” in the guard

i

++

in the LOOP frame

action box

an

may contain arbitrary language

statements

(

in this case

,

incrementing ‘i’

)

it is placed over the lifeline to which it applies

顺序图的基本表示(续)
  • 对集合的迭代

14

slide17

message to class

,

or a

static method call

doX

1

:

locs

=

getAvailableLocales

«metaclass»

:

Foo

Calendar

顺序图的基本表示(续)
  • 对类调用静态方法的消息

17

slide18
顺序图的基本表示(续)
  • 多态消息的案例

18

slide19

a stick arrow in UML implies an asynchronous call

active

object

a filled arrow is the more common synchronous call

System

:

:

ClockStarter

Class

In Java

,

for example

,

an asynchronous call may occur as

follows

:

startClock

//

Clock implements the Runnable interface

Thread t

=

new Thread

(

new Clock

() )

;

create

:

Clock

t

.

start

()

;

the asynchronous

start

call always invokes the

run

method

run

on the

Runnable

(

Clock

)

object

runFinalization

to simplify the UML diagram

,

the

Thread

object and the

start

message may be avoided

(

they are standard

“overhead”

)

;

instead

,

the essential detail of the

Clock

creation and the

run

message imply the asynchronous call

顺序图的基本表示(续)
  • 异步和同步调用

19

slide20
协作图的基本表示法
  • 消息及导航路径

20

slide22

Three ways to show creation in a

communication diagram

create message

,

with optional initializing parameters

.

This will

normally be interpreted as a constructor call

.

1

:

create

(

cashier

)

:

Register

:

Sale

1

:

create

(

cashier

)

:

Register

:

Sale

{

new

}

«create»

1

:

make

(

cashier

)

:

Register

:

Sale

if an unobvious creation message name is used

,

the

message may be stereotyped for clarity

协作图的基本表示法(续)
  • 实例的创建

22

slide25

lineItems

[

i

]:

t

=

getTotal

1

* [

i

=

1

..

n

]:

st

=

getSubtotal

:

Sale

SalesLineItem

This lifeline box represents one instance from a

this iteration and recurrence clause indicates

collection of many

SalesLineItem

objects

.

we are looping across each element of the

lineItems

collection

.

lineItems

[

i

]

is the expression to select one

element from the collection of many

SalesLineItems

;

the ‘i” value comes from the

message clause

.

lineItems

[

i

]:

t

=

getTotal

1

*:

st

=

getSubtotal

:

Sale

SalesLineItem

Less precise

,

but usually good enough to imply

iteration across the collection members

协作图的基本表示法(续)
  • 迭代或循环

25

slide26

message to class

,

or a

static method call

doX

1

:

locs

=

getAvailableLocales

«metaclass»

:

Foo

Calendar

协作图的基本表示法(续)
  • 对类调用静态方法的消息

26

slide30

officially in UML

,

the top format is

used to distinguish the package

SuperclassFoo

name from the class name

or

SuperClassFoo

{

abstract

}

unofficially

,

the second alternative

is common

-

classOrStaticAttribute

:

Int

+

publicAttribute

:

String

3

common

-

privateAttribute

compartments

assumedPrivateAttribute

isInitializedAttribute

:

Bool

=

true

java

.

awt

::

Font

1

.

classifier name

aCollection

:

VeggieBurger

[ * ]

or

attributeMayLegallyBeNull

:

String

[

0

..

1

]

java

.

awt

.

Font

2

.

attributes

finalConstantAttribute

:

Int

=

5

{

readOnly

}

/

derivedAttribute

plain

:

Int

=

0

{

readOnly

}

3

.

operations

bold

:

Int

=

1

{

readOnly

}

+

classOrStaticMethod

()

name

:

String

+

publicMethod

()

style

:

Int

=

0

assumedPublicMethod

()

...

an interface

-

privateMethod

()

shown with a

#

protectedMethod

()

getFont

(

name

:

String

) :

Font

keyword

~

packageVisibleMethod

()

getName

() :

String

«constructor» SuperclassFoo

(

Long

)

...

methodWithParms

(

parm

1

:

String

,

parm

2

:

Float

)

methodReturnsSomething

() :

VeggieBurger

methodThrowsException

()

{

exception IOException

}

«interface»

abstractMethod

()

Runnable

Fruit

abstractMethod

2

()

{

abstract

}

//

alternate

dependency

run

()

finalMethod

()

{

leaf

}

//

no override in subclass

...

synchronizedMethod

()

{

guarded

}

...

interface

implementation

and

subclassing

SubclassFoo

PurchaseOrder

1

...

...

order

run

()

...

...

association with

multiplicities

-

ellipsis “…” means there may be elements

,

but not shown

-

a

blank

compartment officially means “unknown” but as a

convention will be used to mean “no members”

30

slide32

Register

«method»

//

pseudo

-

code or a specific language is OK

...

public void enterItem

(

id

,

qty

)

endSale

()

{

enterItem

(

id

,

qty

)

ProductDescription desc

=

catalog

.

getProductDescription

(

id

)

;

makeNewSale

()

sale

.

makeLineItem

(

desc

,

qty

)

;

makePayment

(

cashTendered

)

}

类图中表示方法体

32

slide33

socket

line notation

Timer

Window

1

uses the

Timer

dependency

line notation

Window

1

interface

Window

2

has a dependency on the

required interface

it has a

Timer

interface when it collaborates

with a

Clock

2

object

«interface»

Clock

2

Timer

...

Window

2

Timer

getTime

()

getTime

()

...

Clock

1

implements and

provides the

Clock

3

Timer

interface

...

Timer

Clock

1

Window

3

getTime

()

...

...

getTime

()

socket

line notation

...

lollipop

notation indicates

Clock

3

implements

and provides the

Timer

interface to clients

Window

3

has a dependency on the

Timer

interface when it collaborates

provided interface

Timer

is a

with a

Clock

3

object

接口

33

slide36

the attribute type may be expressed in

official UML

,

with the template binding

K

parameterized or template

«interface»

syntax requiring an arrow

interfaces and classes

List

or

in another language

,

such as Java

template parameter

K is a

clear

()

...

Board

squares

:

List

<

K Square

>

anonymous class with

or

template binding

complete

squares

:

List

<

Square

>

T

ArrayList

...

elements

:

T

[*]

ArrayList

<

T Square

>

...

clear

()

clear

()

for example

,

the

elements

attribute is an

...

...

array of type T

,

parameterized and bound

before actual use

.

there is a chance the UML

2

“arrow” symbol will

eventually be replaced with something else e

.

g

.

,

=

模板

36