The Models are the Code Executable UML Lecture
The Models are the Code Executable UML Lecture 8 - Interactions and Operations Paul Krause Executable UML
Lecture 8 - Interactions and Operations v Domain-level sequence diagrams v Object-level sequence diagrams v Collaboration diagrams v Operations and the Action Specification Language Executable UML
Use Case Description Use Case Name Make Fuel Delivery Purpose To allow a paying customer to deliver fuel of a selected grade Preconditions The desired fuel grade is available Invariants Tank level >4% tank capacity while pump is on Primary Scenario 1. 2. 3. 4. 5. 6. Postconditions Executable UML 7. At Customer removes nozzle from holster; Attendant enables pump; Customer selects one fuel grade; Pump motor is started; Customer uses trigger to control fuel delivery; Customer replaces nozzle in holster; Pump motor is stopped. least 2 litres of fuel have been delivered
Domain Level Sequence Diagram Forecourt Hardware Interfacing User Interface Fuel Sales Checkout <Boundary> 1: binary. Input. Changes 1: Customer removes nozzle 2: nozzle. Removed 2: 3: request. Pump. Enable 3: Request pump enable 4: alert. Attendant. To. Request. For. Pump. Enable 4: Alert attendant of Customer 5: pump. Enable. Button. Pressed 5: Attendant enables pump 6: pump. Enabled 6: 7: GO creation 7: Create Transaction Item 8: 9: Pump motor enabled 10: Customer presses trigger 8: enable. Pump 9: set. Binary. Output 10: binary. Input. Changes 11: trigger. Depressed 11: 12: Start pumping fuel 13: loop until trigger released 14: Unit of fuel is delivered 15: … Executable UML 12: start. Pumping 13: impellor. Pulse 14: fuel. Unit. Delivered
Object Level Sequence Diagram: Admit In-Patient <<terminator>> Administrator selected. Patient: Patient available. Bed: Bed <<terminator>> Resource Allocation admit. Patient assign. Bed bed. Assigned patient. Now. In. Bed patient. Admitted Executable UML request. Case. Notes <<terminator>> Location Tracking
Object collaboration diagram: Admit Patient Admit In-Patient <<terminator>> Administrator Executable UML selected. Patient: Patient available. Bed: Bed <<terminator>> Resource Allocation <<terminator>> Location Tracking
Object collaboration diagram Admit In-Patient <<terminator>> Administrator 1: admit. Patient selected. Patient: Patient 5: request. Case. Notes 6: patient. Admitted 4: patient. Now. In. Bed 2: assign. Bed available. Bed: Bed 3: bed. Assigned Executable UML <<terminator>> Location Tracking <<terminator>> Resource Allocation
Object collaboration diagram Discharge In-Patient 1: discharge. Patient <<terminator>> selected. Patient: Administrator Patient 4: return. Case. Notes 5: patient. Discharged <<terminator>> Location Tracking 2: release. Bed available. Bed: Bed 3: bed. Released Executable UML <<terminator>> Resource Allocation
Class collaboration diagram admit. Patient <<interface>> Administrator discharge. Patient return. Case. Notes : Patient request. Case. Notes patient. Discharged <<interface>> Location Tracking patient. Admitted patient. Now. In. Bed assign. Bed release. Bed bed. Assigned : Bed bed. Released Executable UML <<interface>> Resource Allocation
Simple Train Example [Raistrick et al, 2004] Acceleration Speed Acceleration Curve 2 Curve 1 Curve 5 Curve 4 Acceleration Curve 6 Curve 3 Hop 1 Hop 2 Distance Executable UML
Train Control Domain Train is currently being negotiated by R 2 0. . 1 is established by 0. . 1 is currently negotiating 0. . 1 is preceded by 0. . 1 R 1 Hop 0. . 1 has established R 4 R 6 has first 0. . 1 1 is followed by is first curve in 0. . 1 R 7 0. . 1 is currently being performed by R 3 has first 1 0. . 1 is currently performing is followed by Acceleration. Curve 0. . 1 R 5 0. . 1 is preceded by Executable UML is first hop in Journey
Class collaboration model negotiate. Hop : Train perform. Curve : Hop hop. Negotiated final. Hop. Negotiated Executable UML : Acceleration. Curve curve. Performed final. Curve. Performed adjust. Speed <<terminator>> : Motor
Assigning class responsibilities At start of jounrey: 1. link myself to first hop 2. ask hop to “negotiate” itself negotiate. Hop : Train final. Hop. Negotiated Executable UML When each Acceleration. Curve (AC) is complete: 1. Unlink that AC from Hop 2. Delete the completed AC 3. Link the next AC (if any) to Hop perform. Curve : Hop hop. Negotiated When each hop is complete: 1. Unlink that Hop from Train 2. Delete the completed Hop 3. Link next Hop (if any) to train : Acceleration. Curve curve. Performed final. Curve. Performed adjust. Speed <<terminator>> : Motor
Policies for the Train Control Domain v Dynamic classes are created “top-down” v Deletion is performed “bottom-up” v Commands are sent “top-down” v Responses are sent “bottom-up” v Unfortunately, it is not always possible to have such simple policies! Executable UML
Modelling Operations v Operations are used to model state-independent behaviour v An operation is the invocation of some action via a parameterised interface v think of a method call in Java or a function call in C v Operations are executed synchronously v the caller waits until the action has been executed and a result returned before continuing v The resulting action may in turn invoke (synchronously) other actions, or asynchronous behaviour by generating signals Executable UML
Generic operation rules v Operations are specified with an Action Specification Language (ASL) v Operations: v are executed synchronously v may have zero or more input parameters v may have zero or more output parameters v may have input and output parameters of any valid data type Executable UML
Types of operation v Object-based v defined in a class v Class-based v may be underlined in a class definition v Domain-based v associated with the domain as a whole v Bridge v used to map the service requirements to the service requirements of one or more other domains Executable UML
Domain operations Fuel Sales A domain based operation can be Shopping invoked by: • any class in its domain • any bridge operation Checkout Forecourt Hardware Interfacing Executable UML User Interface Logging Telecommunications Interface
Class and object operations Pump. Specification Pump Nozzle Executable UML A class or object based operation Filling. Stationcan 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 Fuel. Grade to be “externally visible” Tank
Example object operation calculate. Desired. Speed(distance. Along. Hop: Real = 0. 0): (desired. Speed: Real) Acceleration. Curve curve. ID start. Distance end. Distance desired. Start. Speed desired. End. Speed polling. Timer. ID polling. Rate. Units next. Curve. ID create. Acceleration. Curve calculate. Desired. Speed Executable UML if (distance. Along. Hop = this. Start. Distance) & (this. start. Speed = 0. 0) then the. Train = this -> R 3 -> R 2 desired. Speed = the. Train. minimum. Speed else length. Of. Curve = this. end. Dist - this. start. Dist required. Speed. Diff = this. end. Speed - this. start. Speed speed. Gradient = required. Speed. Diff / length. Of. Curve distance. Along. Curve = dist. Along. Hop - this. start. Dist delta. Speed = distance. Along. Curve * speed. Gradient desired. Speed = delta. Speed + this. start. Speed end if
Invoking an object-based operation Return parameter(s) Key letter for Acceleration. Curve Class Operation number in the class definition [the. Desired. Speed] = AC 2: calculate. Desired. Speed[hop. Distance] on the. Acc. Curve keyword “on” indicates this operation is object based class instance handle Executable UML
Is ASL another programming language? v ASL does not specify software structure anywhere: v no pointers, arrays, lists … v No mechanisms to show v persistence v manner of invocation v manner of distribution of messages v how data is stored v All these are the business of the model compilers as they are platform dependent issues Executable UML
Summary v Behaviour of active objects is specified with state charts v Signals or events induce transitions in an object’s lifecycle v State-independent behaviour is captured in operations v Sequence and collaboration diagrams summarise the signal events and operation calls between objects as they work together to achieve some goal Executable UML
- Slides: 23