36
CSC 450 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

Embed Size (px)

Citation preview

Page 1: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

1

• CSC 450

Slides adapted from slides created by Robert B. France

UML Behavioral Models

Page 2: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

Advanced Modeling with UML 2

Behavioral Elements of UML Metamodel

Page 3: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

3

Specifying behavior using UML Class models describe objects and their

relationships Behavior can be specified in terms of

operation pre and postconditions, but behavior is not the primary focus of a class model

Behavioral models in the UML State models: describe control aspects of a

system – provides descriptions sequences of operations without regard for what the operation do.

Interaction models: describe interactions among objects

Activity models: description of a behavioral feature expressed in terms of sequences of steps.

Page 4: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

4

How things happen in the UML

An action is executed by an object It May

Change the contents of one or more variables Invoke an operation on another object Send a signal to another object Either one will eventually cause the execution of

a procedure on the target object… …which will cause other actions to be executed,

etc. Successor actions are executed

Determined either by control flow or data flow

Page 5: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

5

Sequence Models

Page 6: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

6

Overview Objects interact to accomplish use case

goals. Object interactions are described in terms of

Collaborations: descriptions of object structures that support required behaviors

Interactions: descriptions of communication structures that support required behaviors

A sequence diagram Models sequential logic, an ordered sequence of interactions between objects as described for example, by a use case Interaction/sequence diagrams allow one to

view only the parts of a system involved in accomplishing use case goals.

Page 7: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

7

A class diagram for a Student Registration Application

***** ****** *CourseSection

requestToRegister

RegistrationCourse

getPrerequisite

Student

addToSchedulehasPassedCourseaddToRegistrationList

11 1

Diagram shows structure not behaviour.

Page 8: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

8

Sequence diagrams

A sequence diagram shows the sequence of messages exchanged by the set of objects performing a certain task

The objects are arranged horizontally across the diagram.

An actor that initiates the interaction is often shown on the left.

The vertical dimension represents time. A vertical line, called a lifeline, is attached to each

object or actor. The lifeline becomes a broad box, called an activation

box during the live activation period. A message is represented as an arrow between

activation boxes of the sender and receiver. A message is labelled and can have an argument list and a return

value.

requestToRegister

addToSchedule<<create>>

:Student

:Registration

:CourseSection

addToRegistrationList

Page 9: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

9

Sequence Diagram: basic constructs

objectName : Classobject symbol

lifeline

activation

other:Type

message

name (…)

return

: Class

create

new (…)

delete

m1()

Page 10: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

10

Different kinds of arrows

Synchronous - Procedure call or other kind of nested flow of control

Asynchronous, flat flow

Return

Page 11: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

11

Example: different arrows

caller exchange callee

Flat Flow

lift receiver

dial tone

dial digit

dial digit

ringing tone ringing signal

lift receiver

teller : Order : Article

Nested Flow

getValue

price

getName

1 2

34

5 6

7 8

910

Different traces are possible!

Page 12: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

12

Extended sequence diagram example

requestToRegister(aStudent)

addToSchedule()

aStudent:

Student

:Registration

:CourseSectionGUI

requestToRegister()

:Course

[hasPrerequisite]<<create>>

prereq :=

getPrerequisite()hasPrerequisite:= hasPassedCourse(prereq)

addToRegistrationList()

Page 13: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

13

If an object’s life ends, this is shown with an X at the end of the lifeline

Sequence diagrams – an example with object deletion

cancelBooking

deleteFromItinerarycancel

:PassengerRole:Booking:SpecificFlight

deleteFromPassengerList

Page 14: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

14

sd GoHomeSetup

:ServiceUser:ServiceBase

ref SB_GoHomeSetup:ServiceTerminal

opt

ref FindLocation

SetHome

SetInvocationTime

SetTransportPreferences

refAuthorization

A more complex Sequence Diagram (UML 2.0)

Frame and Name

Lifeline is an object

Interaction Occurrence

Combined Fragment

Plain asynchronous message

sd Authorization

:ServiceUser:ServiceBase

ref SB_Authorization:ServiceTerminal

Code

OK

OnWeb

OK

Page 15: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

15

Combined Fragments

• A combined fragment defines an expression of interaction fragments. A combined fragment is defined by an interaction operator and corresponding interaction operands. Through the use of CombinedFragments the user will be able to describe a number of traces in a compact and concise manner – UML Spec.

Page 16: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

16

Combined Fragment

Page 17: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

17

Combined fragment interaction operators

Alternatives (alt) choice of behaviors – at most one will execute depends on the value of the guard (“else”

guard supported) Option (opt)

Special case of alternative Break (break)

Represents an alternative that is executed instead of the remainder of the fragment (like a break in a loop)

Parallel (par) Concurrent (interleaved) sub-scenarios

Negative (neg) Identifies sequences that must not occur

Page 18: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

18

Combined fragment interaction operators

Critical Region (region) Traces cannot be interleaved with events

on any of the participating lifelines Loop (loop)

Optional guard: [<min>, <max>, <Boolean-expression>]

No guard means no specified limit

Page 19: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

19

Critical region

call(112)

Page 20: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

20

Combined fragments and data: loop

:ServiceUser :ServiceBase :ServiceTerminal

sd GoHomeInvocation(Time invoc)

:Clock

InvocationTime FindLocation

TransportSchedule

loop

alt

ScheduleIntervalElapsedFindLocation

TransportSchedule

GetTransportSchedule

TransportSchedule

FetchSchedule

[Now>interv+last]

[pos-lastpos>dist]

[Now>invoc]

loop

Choice

Operand Separator

Guarding InteractionOperand with an InteractionConstraint

Page 21: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

21

sd ATM-transaction

client: atm: dbase:

Referencing interaction diagrams

insertCard

CheckPinref

alt [chk= OK]

[else]error(badPIN)

DoTransactionref

sd CheckPin

client: atm: dbase:

askForPIN

data(PIN)check(PIN)

result(chk)result(chk)

Interaction Frame Lifeline is one object or a partLifeline is one object or a part

Interaction OccurrenceInteraction Occurrence

Combined (in-line) Fragment

Combined (in-line) Fragment

Page 22: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

22

sd SB_GoHomeSetup

:Central :TimeKeeper

ref SB_Authorization

opt

SetHome

SetInvocationTime

SetTransportPreferences

sd GoHomeSetup

:ServiceUser:ServiceBase

ref SB_GoHomeSetup:ServiceTerminal

opt

ref FindLocation

SetHome

SetInvocationTime

SetTransportPreferences

refAuthorization

Decomposition with global constructs corresponding to

those on decomposed lifeline

ServiceBase

sdSB_GoHomeSetup

sdSB_Authorization

:Central :Authorizer

:TimeKeeper

Decomposed lifeline

Detailed context

Decomposing Lifelines

Page 23: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

23

Local variables:money transfer sequence diagram

Local variables

Page 24: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

24

Creating Interaction Model

Set interaction context Use Case scenario

Identify (controller) object responsible for handling the event initiating the interaction

Identify objects that collaborate with the controller (collaborators).

Specify message passing sequence that handles the initiating message.

Page 25: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

25

Interaction modeling tips

Set the context for the interaction. Include only those attributes of the objects

that are relevant. Express the flow from left to right and from top

to bottom. Put active objects to the left/top and passive

ones to the right/bottom. Use sequence diagrams

to show the explicit ordering between the stimuli

when modeling real-time

Page 26: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

26

Example 1: problem specification

Withdrawing money from an account When withdrawing money from his

account, John inserts his card and inputs his password. He then selects the account from which to withdraw money and enters the amount of money to withdraw. He then collects his money and receipt.

Page 27: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

27

Exercise: create a sequence diagram for a scenario of a self-service machine.

The main functions of a self-service machine is to allow a customer to buy a product(s) from the machine (candy, chocolate, juice...).

A customer wants to buy some of the products offered by the self-service machine.

First of all he/she inserts money into the machine and selects one or more products.

The money travels to the register and the register checks to see whether the selected product is in the dispenser. The register updates its cash reserved and asks the dispenser to deliver the product to the front of the machine.

Page 28: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

28

______________________Devon M. Simmonds

Computer Science Department

University of North Carolina Wilmington

_____________________________________________________________

Qu es ti ons?

The End

Page 29: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

Additional Slides

29

Page 30: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

Money Withdrawal

30

Page 31: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

31

UML Metamodel – Interactions

Page 32: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

32

UML Metamodel – Interactions

Page 33: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

33

Page 34: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

34

Page 35: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

35

Interaction Use

Page 36: 1 CSC 450 Slides adapted from slides created by Robert B. France UML Behavioral Models

CSC450CSC450

36

A simple sequence diagram for a Register Student use case

requestToRegister

addToSchedule<<create>>

:Student

:Registration

:CourseSection

addToRegistrationList

***** ****** *CourseSection

requestToRegister

RegistrationCourse

getPrerequisite

Student

addToSchedulehasPassedCourseaddToRegistrationList

11 1