Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul...

23
Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause

Transcript of Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul...

Page 1: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

The Models are the Code -Executable UML

Lecture 8 - Interactions and Operations

Paul Krause

Page 2: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Lecture 8 - Interactions and Operations

Domain-level sequence diagrams

Object-level sequence diagrams

Collaboration diagrams

Operations and the Action Specification Language

Page 3: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Use Case DescriptionUse Case Name

Purpose

Preconditions

Invariants

Primary Scenario

Postconditions

Make Fuel Delivery

To allow a paying customer to deliver fuel of a selected grade

The desired fuel grade is available

Tank level >4% tank capacity while pump is on

1. Customer removes nozzle from holster;

2. Attendant enables pump;

3. Customer selects one fuel grade;

4. Pump motor is started;

5. Customer uses trigger to control fuel delivery;

6. Customer replaces nozzle in holster;

7. Pump motor is stopped.

At least 2 litres of fuel have been delivered

Page 4: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Domain Level Sequence Diagram

<Boundary>Forecourt Hardware Interfacing User Interface Fuel Sales Checkout

1: binaryInputChanges

2: nozzleRemoved

3:requestPumpEnable

4:alertAttendantToRequestForPumpEnable

5:pumpEnableButtonPressed

6:pumpEnabled

7:GO creation

8:enablePump

9:setBinaryOutput

10:binaryInputChanges

11:triggerDepressed

12:startPumping13:impellorPulse

14:fuelUnitDelivered

1: Customer removes nozzle

2:

3:Request pump enable

4: Alert attendant of Customer

5: Attendant enables pump

6:

7: Create Transaction Item

8:

9: Pump motor enabled

10: Customer presses trigger

11:

12: Start pumping fuel

13: loop until trigger released

14: Unit of fuel is delivered

15: …

Page 5: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Object Level Sequence Diagram:

<<terminator>>Administrator

selectedPatient:Patient

availableBed:Bed

<<terminator>>ResourceAllocation

<<terminator>>LocationTracking

admitPatient

assignBed

bedAssigned

patientNowInBed

requestCaseNotespatientAdmitted

Admit In-Patient

Page 6: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Object collaboration diagram: Admit Patient

<<terminator>>Administrator

selectedPatient:Patient

availableBed:Bed

<<terminator>>ResourceAllocation

<<terminator>>LocationTracking

Admit In-Patient

Page 7: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Object collaboration diagram

<<terminator>>Administrator

selectedPatient:Patient

availableBed:Bed

<<terminator>>ResourceAllocation

<<terminator>>LocationTracking

1: admitPatient 5: requestCaseNotes

2: assignBed

3: bedAssigned

4: patientNowInBed

6: patientAdmitted

Admit In-Patient

Page 8: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Object collaboration diagram

<<terminator>>Administrator

selectedPatient:Patient

availableBed:Bed

<<terminator>>ResourceAllocation

<<terminator>>LocationTracking

1: dischargePatient 4: returnCaseNotes

2: releaseBed

3: bedReleased

5: patientDischarged

Discharge In-Patient

Page 9: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Class collaboration diagram

<<interface>>Administrator

:Patient

:Bed<<interface>>

ResourceAllocation

<<interface>>LocationTracking

dischargePatient returnCaseNotes

releaseBed

bedReleased

patientDischarged

admitPatient

requestCaseNotes

assignBed

bedAssigned

patientNowInBed

patientAdmitted

Page 10: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Simple Train Example [Raistrick et al, 2004]

Hop 1 Hop 2

Acceleration

Curve 1

Acceleration

Curve 2 Acceleration

Curve 3

Acceleration

Curve 4

Acceleration

Curve 5

Acceleration

Curve 6

Speed

Distance

Page 11: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Train Control Domain

Train

Hop

AccelerationCurve

Journey

is established by

0..1

0..1

0..1

0..1

0..1

0..1

0..1

0..1 0..1

1 0..1

0..1

0..1

1

has first is first hop in

is currently beingnegotiated by

is currentlynegotiating

is preceded by

is followed by

is first curve in

has first is currently performing

is currently beingperformed by

is followed by

is preceded by

has established

R1

R2

R3

R4

R5

R6

R7

Page 12: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Class collaboration model

:Train :Hop :AccelerationCurve <<terminator>>:Motor

negotiateHop performCurve

adjustSpeedhopNegotiated curvePerformed

finalHopNegotiated finalCurvePerformed

Page 13: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Assigning class responsibilities

:Train :Hop :AccelerationCurve <<terminator>>:Motor

negotiateHop performCurve

adjustSpeedhopNegotiated curvePerformed

finalHopNegotiated finalCurvePerformed

At start of jounrey:1. link myself to first hop2. ask hop to “negotiate” itself

When each hop is complete:1. Unlink that Hop from Train2. Delete the completed Hop3. Link next Hop (if any) to train

When each AccelerationCurve(AC) is complete:1. Unlink that AC from Hop2. Delete the completed AC3. Link the next AC (if any)

to Hop

Page 14: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Policies for the Train Control Domain

Dynamic classes are created “top-down”

Deletion is performed “bottom-up”

Commands are sent “top-down”

Responses are sent “bottom-up”

Unfortunately, it is not always possible to have such simple policies!

Page 15: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Modelling Operations Operations are used to model state-

independent behaviour

An operation is the invocation of some action via a parameterised interface think of a method call in Java or a function call in C

Operations are executed synchronously the caller waits until the action has been executed

and a result returned before continuing

The resulting action may in turn invoke (synchronously) other actions, or asynchronous behaviour by generating signals

Page 16: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Generic operation rules

Operations are specified with an Action Specification Language (ASL)

Operations: are executed synchronously may have zero or more input parameters may have zero or more output parameters may have input and output parameters of any

valid data type

Page 17: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Types of operation

Object-based defined in a class

Class-based may be underlined in a class definition

Domain-based associated with the domain as a whole

Bridge used to map the service requirements to the

service requirements of one or more other domains

Page 18: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Domain operations

Fuel Sales Shopping

ForecourtHardwareInterfacing

Checkout

User Interface LoggingTelecommunications

Interface

A domain based operation can be invoked by:• any class in its domain• any bridge operation

Page 19: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Class and object operations

Pump

PumpSpecification FillingStation

Nozzle Tank

FuelGrade

A class or object based operation can be invoked by:• any class or class instance in its domain• any domain based operation associated with its domain• any bridge operation if it is declared to be “externally visible”

Page 20: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Example object operation

AccelerationCurve

curveIDstartDistanceendDistancedesiredStartSpeeddesiredEndSpeedpollingTimerIDpollingRatepollingRateUnitsnextCurveID

createAccelerationCurvecalculateDesiredSpeed

if (distanceAlongHop = thisStartDistance) & \ (this.startSpeed = 0.0) then theTrain = this -> R3 -> R2 desiredSpeed = theTrain.minimumSpeed

else lengthOfCurve = this.endDist - this.startDist requiredSpeedDiff = this.endSpeed - this.startSpeed speedGradient = requiredSpeedDiff / lengthOfCurve distanceAlongCurve = distAlongHop - this.startDist deltaSpeed = distanceAlongCurve * speedGradient desiredSpeed = deltaSpeed + this.startSpeed

end if

calculateDesiredSpeed(distanceAlongHop:Real = 0.0):(desiredSpeed:Real)

Page 21: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Invoking an object-based operation

[theDesiredSpeed] = AC2:calculateDesiredSpeed[hopDistance] on theAccCurve

Return parameter(s)

Key letter for AccelerationCurve Class

Operation number in the class definition

class instance handle

keyword “on” indicates this operation isobject based

Page 22: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Is ASL another programming language?

ASL does not specify software structure anywhere: no pointers, arrays, lists …

No mechanisms to show persistence manner of invocation manner of distribution of messages how data is stored

All these are the business of the model compilers as they are platform dependent issues

Page 23: Executable UML The Models are the Code - Executable UML Lecture 8 - Interactions and Operations Paul Krause.

Executable UML

Summary

Behaviour of active objects is specified with state charts

Signals or events induce transitions in an object’s lifecycle

State-independent behaviour is captured in operations

Sequence and collaboration diagrams summarise the signal events and operation calls between objects as they work together to achieve some goal