36
INF5120 Model based System Development 24.01.2011 1 Telecom and Informatics 1 INF5120 ”Modellbasert Systemutvikling” ”Modelbased System development” Lecture 6: 20.02.2012 Arne-Jørgen Berre [email protected] or [email protected] Telecom and Informatics 2 INF5120 - Lecture plan - 2012 Part I: SSI Service Innovation and Agile Service/Software Engineering Part II: SSMDE Model Driven Engineering Part III Model Driven Interoperability and ADM 1: 16/1: Introduction to Model Based System Development (INF5120) 2: 23/1: SIE I: Enterprise Architecture, Role modeling-Collaboration and Value Networks Verna Allee (VNA) 3: 30/1: SIE II:: Business Process Modeling with BPMN 2.0 and Business Model Innovation - Peter Lindgren (BMI) 4: 6/2: SIE III: AT ONE User-oriented design with Use cases and user stories 5: 13/2: SIE IV: Service modeling with SoaML Service modeling - Design, patterns 6: 20/2: SIE V: Precise Modeing in UML with OCL and Design with DCI - Design, patterns 7: 27/2: MDE I: Software Process Model Frameworks Essence/SEMAT, SPEM, EPF and ISO 24744 Shihong Huang/Brian Elvesæter/Arne J. Berre 8: 5/3: MDE II: Metamodels, Domain specific languages and UML profiles (Franck Fleurey, Brian Elvesæter) 9: 12/3: MDE III: Metamodeling, MDLE and DSL Tools (EMF, GMF, ATL, Kermeta) (Franck Fleurey) 10: 19/3: MDE IV: Model transformations - MOFScript, QVT DSLs with examples (Franck Fleurey) 11: 26/3: MDE V: Internet Service Architectures - and Method Engineering (Arne J. Berre) 2/4, 9/4: EASTER 12: 16/4: MDE VI: User Interface Modeling IFML etc. - ESITO 13: 23/4: MDI I: Semantic technologies, Ontologies and Semantic annotations , Rules/SBVR 14: 30/4: MDI II: Model Driven Service Interoperability 15: 7/5: MDI III: ADM and Migration to Cloud computing 16: 13/5: Conclusion and Summary for INF5120 - Preparation of Exam Exam: Monday June 4th, 2011, 1430-1830 (4 hours)

”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

1

Telecom and Informatics 1

INF5120

”Modellbasert Systemutvikling”

”Modelbased System development”

Lecture 6: 20.02.2012 Arne-Jørgen Berre

[email protected] or [email protected]

Telecom and Informatics 2

INF5120 - Lecture plan - 2012

Part I: SSI – Service Innovation and Agile Service/Software Engineering

Part II: SSMDE – Model Driven Engineering

Part III – Model Driven Interoperability and ADM

1: 16/1: Introduction to Model Based System Development (INF5120)

2: 23/1: SIE I: Enterprise Architecture, Role modeling-Collaboration and Value Networks – Verna Allee (VNA)

3: 30/1: SIE II:: Business Process Modeling with BPMN 2.0 and Business Model Innovation - Peter Lindgren (BMI)

4: 6/2: SIE III: AT ONE –User-oriented design – with Use cases and user stories

5: 13/2: SIE IV: Service modeling with SoaML – Service modeling - Design, patterns

6: 20/2: SIE V: Precise Modeing in UML with OCL and Design with DCI - Design, patterns

7: 27/2: MDE I: Software Process Model Frameworks – Essence/SEMAT, SPEM, EPF and ISO 24744 –Shihong Huang/Brian Elvesæter/Arne J. Berre

8: 5/3: MDE II: Metamodels, Domain specific languages and UML profiles (Franck Fleurey, Brian Elvesæter)

9: 12/3: MDE III: Metamodeling, MDLE and DSL Tools (EMF, GMF, ATL, Kermeta) (Franck Fleurey)

10: 19/3: MDE IV: Model transformations - MOFScript, QVT DSLs with examples (Franck Fleurey)

11: 26/3: MDE V: Internet Service Architectures - and Method Engineering (Arne J. Berre)

2/4, 9/4: EASTER

12: 16/4: MDE VI: User Interface Modeling – IFML etc. - ESITO

13: 23/4: MDI I: Semantic technologies, Ontologies and Semantic annotations , Rules/SBVR

14: 30/4: MDI II: Model Driven Service Interoperability

15: 7/5: MDI III: ADM and Migration to Cloud computing

16: 13/5: Conclusion and Summary for INF5120 - Preparation of Exam

Exam: Monday June 4th, 2011, 1430-1830 (4 hours)

Page 2: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

2

Telecom and Informatics 3

INF5120 – Oblig/Exercise plan - 2012

1: 16/1: None

2: 23/1: Guest lecture: Value Networks – Verna Allee (VNA)

3: 30/1: Guest lecture: Business Model Innovation - Peter Lindgren (BMI) – Establish groups

4: 6/2: AT ONE initial exercise – overall approach for Oblig 1 – “myServiceFellow”

5: 13/2: Group presentation

6: 20/2: Group presentation

7: 27/2: Group presentation

8: 5/3: MDE Tools – introduction – Oblig 2 intro

9: 12/3: MDE Tools II - EMF

10: 21/3: MDE Transformation tools - Delivery of Oblig 1

11: 26/3: Walk through of Oblig 1

2/4, 9/4: EASTER

12: 16/4: MDE User Interface tools – ESITO o.a.

13: 23/4: Oblig 2 questions

14: 30/4: Oblig 2 delivery

15: 7/5: Oblig 2 summary

16: 13/5: Conclusion and Summary for INF5120 - Preparation of Exam

Exam: Monday June 4th, 2011, 1430-1830 (4 hours)

Telecom and Informatics

Outline

SoaML – part 2 – composite structures

Modelio – and support for UML 2, SoaML and BPMN

Precise Modeling and use of UML OCL

Roles and DCI

Scala – and support for roles and DCI through Traits

Software Process Engineering Metamodels (next lecture)

Oblig 1 – presentations and delivery

Page 3: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

3

Telecom and Informatics

Individual exercise – until February 13th

Download myServiceFellow on a SmartPhone, iPhone or

Android (from the respective AppStore).

Identifiy and evaluate touchpoints related to service

interaction points you know about in the context of

University of Oslo and Institute for Informatics

Think both about touchpoints that can be incrementally

improved and radically improved (i.e. new

apps/applications etc.)

Document your touchpoint evaluations using the app

myServiceFellow

5

Telecom and Informatics

Service Design – ”My University”

Actors - Value Networks, Role models – VNA, Verna Allee

Service/Customer Journey – BPMN, Role play,

Touchpoints - UI sketches – Experiences – UI sketches

Opportunities and Needs

Identified services – SoaML – collaboration diagrams

Specificed services – SoaML - composite diagrams

13/2: Touchpoint identification, customer journey (All)

20/2: Actors and Role models, Value Networks, Role play

27/2: BPMN diagrams, initial SoaML diagrams

19/3-26/3: Final group delivery Oblig 1

6

Page 4: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

4

Telecom and Informatics

Requirements for the Oblig 1 delivery

A group delivery – one document per group - containing

your models for your selected area of interest.

Actors – Role models, CRC cards, – Interactive Role play,

Value Network analysis

Customer/User/Service journey, BPMN, User stories/use

cases

Touchpoints – Service descriptions/specifications, SoaML

and UML for information exchange

Opportunities/Needs – match/mismatch ?

Experiences – Service experiences, User Interface

sketches

Voluntary: Any comments on Business Model Innovation

7

Methodology: inf5120.modelbased.net

Telecom and Informatics

Use of tools in Oblig 1

Value Networks – VNA www.valuenetworks.com

Ideas – Sticky/coloured notes in Symphonical – AT ONE

workshop results

Service journeys – BPMN in Modelio

Service Models – SoaML in Modelio

Service Information models – SoaML/UML in Modelio

8

Page 5: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

5

Telecom and Informatics 9

Next Lecture – February 27th, 2012

Software Process Engineering metamodels

SPEM

ISO 24744

SEMAT

Oblig 1 – Group presentations, BPMN and SoaML

Telecom and Informatics

10

Service ports and service participants

A Service port: is the offer of a service by one participant to others using well defined terms,

conditions and interfaces

defines the connection point through which a Participant offers its capabilities and provides a service to clients.

It is defined using a UML Port on a Participant, and stereotyped as a <<Service>>

A Service port is a mechanism by which a provider Participant makes available services that meet the needs of consumer requests as defined by ServiceInterfaces, Interfaces and ServiceContracts.

Page 6: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

6

Telecom and Informatics

11

ServiceInterfaces and

Participants Metamodel

Telecom and Informatics

12

ServiceInterfaces and

Participants Profile

Page 7: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

7

Telecom and Informatics

UML Composite Diagrams

Composite Diagrams

A composite structure diagram is a diagram that shows

the internal structure of a classifier, including its interaction

points to other parts of the system. It shows the

configuration and relationship of parts, that together,

perform the behavior of the containing classifier.

classes can be displayed as composite elements exposing

interfaces and containing ports and parts.

13

Start - Explanation of standard UML 2.3

Telecom and Informatics

Part

A part is an element that represents a set of one or more

instances which are owned by a containing classifier

instance. So for example, if a diagram instance owned a

set of graphical elements, then the graphical elements

could be represented as parts; if it were useful to do so, to

model some kind of relationship between them. Note that

a part can be removed from its parent before the parent is

deleted, so that the part isn't deleted at the same time.

A part is shown as an unadorned rectangle contained

within the body of a class or component element.

14

Page 8: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

8

Telecom and Informatics

Ports

A port is attached to an active class.

The port has:

A name.

An interface specifying the signals that can be received.

An interface specifying the signals that can be sent.

Two types of ports:

Connected to internal communication channels (by default).

Connected to the state machine for the class instance (a behaviour port).

A behaviour port

In interface

Out interface

Telecom and Informatics

Composite Structure

A composite structure diagram shows the relationship among internal

components of a class, in terms of communication paths.

The class may have one or more communications ports through which

signals can be sent or received.

The ports are connected either to:

Internal components

Channels connect the ports of the class to the ports of the

internal components.

Channels can be unidirectional (one direction only) or

bidirectional (both directions).

The state machine behaviour of the class (a behaviour port).

Page 9: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

9

Telecom and Informatics

Object instance references

instance name

class name

Telecom and Informatics

Composite Structure

Page 10: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

10

Telecom and Informatics 19

Composite class (incomplete)

with parts, ports and connectors

ATM

:CardReader

:CashDispenser:Keyboard

User-Reader

User-Keyboard

ATM-bank

User-Cash

:ScreenUser-Screen

part

port

connector

Telecom and Informatics 20

Context Model in UML2.0 - I

composite structure as part of a Collaboration

BankContext

:User :ATM :Bank

User-Reader

User-Keyboard

ATM-bank

User-Cash

User-Screen

Page 11: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

11

Telecom and Informatics 21

Context Model in UML2.0 - II

Including multiplicities on parts

BankContext

:User

[1..10000]

:ATM

[1..100] :Bank

User-Reader

User-Keyboard

ATM-bank

User-Cash

User-Screen

multiplicity

End - Explanation of standard UML 2.3

Telecom and Informatics

22

Service interface

A ServiceInterface:

can type a service port.

can specify a bi-directional service

(both the provider and consumer

have responsibilities to send and

receive messages and events).

A ServiceInterface is defined

from the perspective of the

service provider using three

primary sections:

provided and required Interfaces

ServiceInterface class

protocol Behavior.

Page 12: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

12

Telecom and Informatics

23

Participant with service and request ports

A Service Port is typed by a ServiceInterface

A Request port is typed by a conjugate ServiceInterface (defines the use of a service rather than its provision). This will allow us to connect service providers and consumers in a Participant.

Can be transformed to the appropriate interface/implementation code.

Telecom and Informatics

Interfaces for Participants Each role in the service

that receives interactions

has an interface, this is

the interface for a logical

technology component

and is implemented by

components providing or

using this service. This

service is bi-directional -

messages flow in both

directions.

Interfaces will correspond with parts of WSDL in a web services

mapping of SoaML

Page 13: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

13

Telecom and Informatics

Logical System Components Components

implement the

service interfaces

providing the link

to systems.

Participants and

services may be

used in multiple

architectures.

“Ports” on the participating components

provide and require the service interfaces

for each service provided or used

Telecom and Informatics

Composite Application Components

Components can be assembled from other components by

linking their services. This corresponds to the architecture for

Acme.

Enterprise systems can be integrated

with adapter components

Or, new implementation can be

defined inside of components.

This component is defined as a

composition of other components.

Page 14: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

14

IKT 27

Model examples

ThiNgami

nos

knnn

doZzzkf()

karPhew(zAA)

Editor

text

font

changeFont(font)

addElem(elem)

spellCheck()

NuclearReactorCore

add(ControlRod, int)

ControlRod remove(int)

IKT 28

Precise modeling – Details in models

Avoid misunderstanding

Completeness

Baseline for code generation

Model analysis

Consistence among models

Relationships and mappings between models

Analysis of models

Page 15: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

15

IKT 29

Simplify with OCL

Flight Airplane

CargoFlight PassengerFlight

PasssengerPlane CargoPlane 1

0..*

1

0..*

0..*

1 flights

IKT 30

Diagram with invariants

context Flight

inv: type = #cargo implies airplane.type = #cargo

inv: type = #passenger implies airplane.type = #passenger

1 0..* Flight Airplane

type =

enum{cargo, passenger}

type =

enum{cargo, passenger}

flights

Page 16: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

16

IKT 31

Definition of constraint

“A constraint is a restriction on one or more values of (part

of) an object-oriented model or system.”

IKT 32

Object Constraint Language - OCL

OCL er del av UML

Tekstlig språk for å beskrive beskrankninger

Predikatlogikk gjort folkelig (ingen )

Constraints

begrensninger på modellene

multiplisitet, etc er begrensinger!

ønsker ytterligere begrensninger

Brukes i definisjonen av UMLs metamodell

må jo være presis!

Formelt

entydig

ingen side-effekter

Page 17: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

17

IKT 33

Example model

Airport

Flight

Passenger

Airline

*

*

*

*

$minAge: Integer

age: Integer

needsAssistance: Boolean

departTime: Time

/arrivalTime: Time

duration : Interval

maxNrPassengers: Integer

origin

desti-

nation

name: String

name: String

{ordered}

arriving

Flights

departing

Flights

CEO

0..1

flights

passengers

book(f : Flight)

0..1

airline

airline

IKT 34

Constraint context and self

Every OCL expression is bound to a specific context.

The context may be denoted within the expression using

the keyword ‘self’.

Who?

Me?

Page 18: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

18

IKT 35

Notation

Constraints may be denoted within the UML model or in a

separate document.

the expression:

context Flight inv: self.duration < 4

is identical to:

context Flight inv: duration < 4

is identical to:

Flight

duration: Integer <<invariant>>

duration < 4

IKT 36

Elements of an OCL expression

In an OCL expression these elements may be used:

basic types: String, Boolean, Integer, Real.

classifiers from the UML model and their features

attributes, and class attributes

query operations, and class query operations

associations from the UML model

Page 19: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

19

IKT 37

OCL types

Collection

Set Bag Sequence

OclType Real

Integer

String Boolean

OclState

OclExpression

OclAny

IKT 38

Example: OCL basic types

context Airline inv:

name.toLower = ‘klm’

context Passenger inv:

age >= ((9.6 - 3.5)* 3.1).abs implies

mature = true

Page 20: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

20

IKT 39

Model classes and attributes

“Normal” attributes

context Flight inv:

self.maxNrPassengers <= 1000

Class attributes

context Passenger inv:

age >= Passenger.minAge

IKT 40

Example: query operations

context Flight inv:

self.departTime.difference(self.arrivalTime)

.equals(self.duration)

Time

difference(t:Time):Interval

before(t: Time): Boolean

plus(d : Interval) : Time

Interval

equals(i:Interval):Boolean

$Interval(d, h, m : Integer) :

Interval

$midnight: Time

month : String

day : Integer

year : Integer

hour : Integer

minute : Integer

nrOfDays : Integer

nrOfHours : Integer

nrOfMinutes : Integer

Page 21: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

21

IKT 41

Example: navigations

Navigations

context Flight

inv: origin <> destination

inv: origin.name = ‘Amsterdam’

context Flight

inv: airline.name = ‘KLM’

IKT 42

Basic “Navigation” expressions

i: Instructor, c: Course, s: Session

The name of the course:

c.name

The date of the session:

s.date

The instructor assigned to the session:

s.instructor

The course of the session:

s.course

The name of the course of the session:

s.course.name

The instructors qualified for the session:

s.course.qualifiedInstructors

Instructor

name

Course

name

Session

date

qualifiedInstructors qualifiedFor

assignedTo *

0..1

*

* *

Let’s navigate on a model

Page 22: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

22

IKT 43

Navigation Example

What does a1.r1.r2.r3 yield?

Assuming the B’s have a boolean attribute “black”; black=false for b6, b8 -

what expression refers from a2 to the set { b1 }

r2

a

* *

* 1

0..1 1

A B C

c1

c2

c3

c4

a1

a2

r3 r1

b1

b2

b3

b4

b5

b6

b7

b8

IKT 44

Association classes

context Person inv:

if employer.name = ‘Klasse Objecten’ then

job.type = #trainer

else

job.type = #programmer

endif

Person Company

Job

* 1

employee employer

type : {trainer, programmer}

name : String

Page 23: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

23

IKT 45

Three subtypes to Collection

Set:

arrivingFlights(from the context Airport)

Bag:

arrivingFlights.duration (from the context Airport)

Sequence:

passengers (from the context Flight)

IKT 46

OCL has a great number of predefined operations on the

collections types.

Syntax:

collection->operation

Collection operations

Page 24: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

24

IKT 47

The collect operation

Syntax: collection->collect(elem : T | expr)

collection->collect(elem | expr)

collection->collect(expr)

Shorthand: collection.expr

The collect operation results in the collection of the values resulting evaluating expr for all elements in the collection

IKT 48

The select operation

Syntax:

collection->select(elem : T | expression)

collection->select(elem | expression)

collection->select(expression)

The select operation results in the subset of all elements

for which expression is true

Page 25: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

25

IKT 49

The forAll operation

Syntax:

collection->forAll(elem : T | expr)

collection->forAll(elem | expr)

collection->forAll(expr)

The forAll operation results in true if

expr is true for all elements of the

collection

IKT 50

The exists operation

Syntax:

collection->exists(elem : T | expr)

collection->exists(elem | expr)

collection->exists(expr)

The exists operation results in true if

there is at least one element in the

collection for which the expression expr

is true.

Page 26: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

26

IKT 51

Example: exists operation

context Airport inv:

self.departingFlights ->

exists(departTime.hour < 6)

IKT 52

Other collection operations

isEmpty: true if collection has no elements

notEmpty: true if collection has at least one element

size: number of elements in collection

count(elem): number of occurences of elem in collection

includes(elem): true if elem is in collection

excludes(elem): true if elem is not in collection

includesAll(coll): true if all elements of coll are in collection

Page 27: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

27

IKT 53

Iterate example

Example iterate: context Airline inv:

flights->select(maxNrPassengers > 150)->notEmpty

Is identical to: context Airline inv:

flights->iterate(f : Flight; answer : Set(Flight) = Set{ } |

if f.maxNrPassengers > 150 then

answer->including(f)

else answer endif )->notEmpty

IKT 54

OCL — Navigation Details

An association end with cardinality maximum > 1 yields a set or

sequence

anInstructor.Session yields a sequence

anInstructor.qualifiedFor yields a set

An association end with cardinality maximum of 1 yields an object or a

set (with zero or one elements)

aSession.Instructor yields an object

aSession.Instructor->isEmpty yields a Boolean

*

*

qualifiedFor

Instructor

qualifiedFor

Course

qualifiedInstructors

Session

date

evaluation

* {seq}

*

0..1

Page 28: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

28

IKT 55

Collections use

i: Instructor

The courses an instructor is qualified to teach

Course.allInstances ->select ( c | c.qualifiedInstructors ->includes ( i ))

Sessions delivered by an instructor who is no longer qualified to teach it

Session.allInstances ->select ( s | s.delivered and

s.course.qualifiedInstructors ->excludes ( s.instructor ) )

The last can be simplified significantly with “convenience” attributes

Session.allInstances ->select ( s | s.teacherNotQualified )

Instructor

name

Course

name

Session

date

delivered

qualifiedInstructors qualifiedFor

assignedTo

* 0..1

*

* *

Let’s navigate on a model

IKT 56

Another Invariant Formalized

Always combine formal and narrative descriptions

-- for every instructor ...

Instructor::invariant

-- for any course

Course.allInstances->forAll ( c |

-- if the evaluation bad

Session->select(Course=c)->forAll(s |

s.evaluation = bad

-- then instructor is disqualified for course

implies qualifiedFor ->excludes (c)) )

Instructor

Course

*

*

qualifiedFor

Session

date

evaluation

* {seq}

*

qualifiedInstructors

Page 29: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

29

IKT 57

Same Invariant on Course

-- for every course ...

Course::invariant

-- for all sessions

Session->forAll ( s |

-- if the evaluation is bad

s.evaluation = bad implies

-- then the instructor is not a qualified instructor

qualifiedInstructors->excludes(s.Instructor) )

Instructor

Course

*

*

qualifiedFor

Session

date

evaluation

* {seq}

*

qualifiedInstructors

IKT 58

Operation Specification

operation SeminarSystem::pay (in client:Client, out amount: Money)

-- When you pay off an invoice

pre -- Provided the payment amount is not negative and does not

-- exceed amount owed

client .balance >= amount and amount>=0

post -- The balance is reduced by the amount of the payment

client.balance@pre = client.balance + amount

SeminarSystem

pay(client:Client, amount: Money)

Client

balance

Page 30: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

30

IKT 59

let, new: Convenient Names, New Objects

Any specification can introduce local names using let … in ...

operation SeminarSystem::scheduleCourse

(client: Client, date: Date, course: Course)

let ( availableInstructors =

instructors ->select (qualifiedFor(course) and availableOn(date)) )

in ( -- the name “availableInstructors” can be used in pre or post

pre availableInstructors ->notEmpty

post -- some instructor from available instructors is assigned …

)

Actions often result in the creation of a new object

let (s = Session.new) in ( -- s is a new member of Session type

s.client = client and s.date = date and s.course = course

and ….

)

IKT 60

OCL — Misc.

Special words

@pre designates a value at the start of an operation

total = total@pre + amount

self designates the object itself

self.total = self.total@pre + amount

result designates the returned object (if any)

result = total

Comments

-- Two hyphens start a comment that goes through the end of line

Page 31: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

31

IKT 61

OCL Tools

Cybernetics ww.cybernetic.org

University of Dresden www-st.inf.tu-dresden.de/ocl/

Boldsoft www.boldsoft.com

ICON computing www.iconcomp.com

Royal Dutch Navy

Others … …

IKT 62

Conclusions and Tips

OCL invariants allow you to model more precisely

stay implementation independent

OCL pre- and postconditions allow you to specify contracts (design by contract)

precisely specify interfaces of components

OCL usage tips keep constraints simple

always combine natural language with OCL

use a tool to check your OCL

Page 32: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

32

IKT 63

Diskusjon

Sett dere sammen i grupper på 2-3 og diskuter følgende:

Vil OCL være et nyttig bidrag i noen av deres modeller? På hvilken

måte?

Kan dere gi eksempler fra øvingsoppgaven hvor OCL ville ha øket

presisjonen i deres modeller?

Er det noen ulemper med bruk av OCL?

IKT 64

UML og OCL

Skriver OCL som tilleggsdokumentasjon til

modeller

Skriver OCL i Constraints

(Verktøy)problem: hvordan bruke aktivt

forfining

konsistens

kodegenerering

Page 33: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

33

IKT 65

Further resources on OCL

The Object Constraint Language

ISBN 0-201-37940-6

OCL home page

www.klasse.nl/ocl/index.htm

IKT 66

OclAny

x,y:OclAny; T is a OclType

x = y

x < > y

x.oclIsNew

x.oclType

x.isKindOf(T)

x.isTypeOf(T)

x.asType(T)

x and y are the same object

not (x=y)

True if x is a new instance

The type of x

True if T is a supertype (transitive) of

the type of x

True if T is equal to the type of x

Results in x, but of type T.

Page 34: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

34

IKT 67

OclType and operators

Logical operators in Boolean expressions

and, or, xor, not, implies

T is a OclType

T.new

T.allInstances

Create a new instance of type T

All of the instances of type T

IKT 68

Collection (1)

c,c2 : Collection(T); x,e:T; P:T Boolean;

f, f2: T Object

c->size Number of elements

c->sum Sum of elements (elements

must support addition)

c->count(e) Number of times e is in c

c->isEmpty c->size = 0

c->notEmpty not c->isEmpty

Page 35: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

35

IKT 69

Collection (2)

c->includes(e) True if e is in c

c->includesAll(c2) True if c2 in c

c->excludes(e) True if e not in c

c->exludesAll(c2) True if none in c2 is in c

c->exists(P) True if an e makes P true

c->forAll(P) True if P true for all e in c

c->isUnique(f) True if f evaluates to

different value for all e in c

c->sortedBy(f) Sequence sorted by f

c->iterate(x;e=f;f2) Iterate x over c and apply f2,

initialise e to f

IKT 70

Collection subtypes (1)

Applies to set and bag

set, bag: Collection; e,x:T; P: TBoolean;

f, f2: TObject

set->union(set2)

set->union(bag)

set = set2

set->intersection(set2)

set->intersection(bag)

set – set2

set->including(e)

Page 36: ”Modellbasert Systemutvikling” ”Modelbased System development” · UML Composite Diagrams Composite Diagrams A composite structure diagram is a diagram that shows the internal

INF5120 Model based System Development 24.01.2011

36

IKT 71

Collection subtypes (2)

set->excluding(e)

set->symmetricDifference(set2)

The set of elements in set or set2,

but not in both

set->select(x|P) All elements for which P is valid

set->select(P) Same as set->select(self|P)

set->reject(x|P) Same as set->select(x|not P)

set->reject(P) Same as set->select(self|not P)

set->collect(x|f) The bag of elements which results

from applying f to every member of

set

set->asSequence

set->asBag

IKT 72

Sequence

seq->append(e) seq followed by e

seq->prepend(e) e followed by seq

seq->subSequence(lower, upper)

Subsequence in

range [lower, upper]

seq->at(i) Element at position i

seq->first seq->at(1)

seq->last seq->at(seq->size)