+ All Categories
Home > Documents > Einführung in OCL (Object Constraint...

Einführung in OCL (Object Constraint...

Date post: 05-Jun-2018
Category:
Upload: truongnga
View: 225 times
Download: 0 times
Share this document with a friend
33
Fakultät Informatik, Institut SMT, Lehrstuhl Softwaretechnologie Einführung in OCL (Object Constraint Language) Dr Birgit Demuth Dr. Birgit Demuth It is commonly thought that 10 years is needed for technology to pass from its initial conception into wide–spread use. W E Riddle W. E. Riddle The magic number eighteen plus or minus three: a study of software technology maturation. SIGSOFT Softw Eng Notes 9(2):2137 1984 SIGSOFT Softw. Eng. Notes 9(2):21 37, 1984 Dr. Birgit Demuth SWT II, WS 2012/13 2
Transcript
Page 1: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Faku

ltät

In

form

atik

, In

stit

ut

SM

T, L

ehrs

tuh

l Sof

twar

etec

hn

olog

ie

Einf

ühru

ng in

OCL

(Obj

ect

Con

stra

int

Lang

uage

)

Dr

Birgi

tD

emut

hD

r. B

irgi

t D

emut

h

It is

com

mon

ly t

houg

ht t

hat

10 y

ears

is n

eede

d fo

r te

chno

logy

to

pass

fro

m it

s in

itial

con

cept

ion

into

wid

e–sp

read

use

.

WE

Rid

dle

W.

E. R

iddl

eTh

e m

agic

num

ber

eigh

teen

plu

s or

min

us t

hree

: a

stud

y of

sof

twar

e te

chno

logy

mat

urat

ion.

SIG

SO

FTSof

twEn

gN

otes

9(2)

:21–

3719

84SIG

SO

FTSof

tw.

Eng.

Not

es 9

(2):

2137

, 19

84

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

132

Page 2: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Was

wol

len

wir le

rnen

?

•Ei

nfüh

rung

in d

ie T

hem

atik

(Ver

trag

smod

ell,

Zus

iche

rung

en,

Übe

rblic

k O

CL)

Spr

achk

onze

pte

und

OCL

byEx

ampl

e“•

Spr

achk

onze

pte

und

„OCL

byEx

ampl

e“–

OCL-

Type

n un

d O

CL-

Aus

drüc

ke–

Wei

tere

OCL-

Anw

eisu

ngen

Wei

tere

OCL

Anw

eisu

ngen

•Anw

endu

ngsf

älle

für

OCL

und

Dis

kuss

ion

•O

CL

Tool

s

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

133

EIN

FÜH

RU

NG

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

134

Page 3: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Theo

retis

che

Gru

ndla

gen

Theo

retis

che

Gru

ndla

gen

•H

oare

-Tri

pel

{ P

} S {

Q }

[H

oare

, 19

69],

z.B

.{x

=y}

y:=

y-x+

1 {y

=1}

•D

esig

n b

yC

ontr

act

(Ver

trag

smod

ell)

[M

eyer

, 19

97],

Ü

bert

ragu

ng a

uf K

lass

en u

nd M

etho

den

–W

enn

die

Kla

sse

K1

eine

Met

hode

Mde

rKla

sse

K2

inAns

pruc

hni

mm

t,m

uss

K1

sich

erst

elle

n,da

ssvo

rAus

führ

ung

von

Mde

ren

Vor

bedi

ngun

gen

erfü

lltis

t.Aus

führ

ung

von

Mde

ren

Vor

bedi

ngun

gen

erfü

lltis

t.K2

gara

ntie

rtda

nn,

dass

nach

Abs

chlu

ssde

rM

etho

deM

die

Nac

hbed

ingu

nggi

lt.

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

135

Zus

iche

rung

en

•V

orb

edin

gu

ng

:–

gara

ntie

rt d

ie „

Kun

denk

lass

e“g

•N

ach

bed

ing

un

g:

gara

ntie

rtdi

eAnb

iete

rkla

sse“

–ga

rant

iert

die

„Anb

iete

rkla

sse

•K

lass

enin

vari

ante

:–

mus

s vo

n al

len

Met

hode

n de

r Anb

iete

rkla

sse

eing

ehal

ten

wer

den

(vor

und

nac

h je

der

Met

hode

naus

führ

ung)g

–gi

lt w

ähre

nd d

er g

esam

ten

Lebe

nsda

uer

der

Obj

ekte

der

Kla

sse

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

136

Page 4: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Form

ulie

rung

von

Zus

iche

rung

en

•M

odel

lbas

iert

:–

OCL

•In

Pro

gram

mie

rspr

ache

n:–

EIFF

E L–

JASS (

Java

with

ASSer

tions

)–

JML

(Jav

a M

odel

ing

Lang

uage

)Ja

va(a

sser

t)–

Java

(as

sert

)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

137

OCL

(Obj

ect

Con

stra

int

Lang

uage

)•

ergä

nzt

Mod

ellie

rung

sspr

ache

n (U

ML)

, hy

brid

e Spr

ache

•fo

rmal

e Spr

ache

für

die

Def

initi

on v

on C

onst

rain

ts(Z

usic

heru

ngen

) un

d Anf

rage

n au

f U

ML-

Mod

elle

n•

stan

dard

isie

rt (

OM

G),

der

zeit

OCL

2.3.

1 (J

anua

ry20

12)

•de

klar

ativ

•de

klar

ativ

•se

itene

ffek

tfre

i•

t ypi

sier

typ

•fü

gt g

raph

isch

en (

UM

L-)M

odel

len

präz

isie

rte

Sem

antik

hin

zu•

vera

llgem

eine

rt f

ür a

lle M

OF-

basi

erte

n M

etam

odel

le

•in

zwis

chen

allg

emei

n ak

zept

iert

, vi

ele

Erw

eite

rung

en•

„Cor

e La

ngua

ge“

von

Mod

elltr

ansf

orm

atio

nssp

rach

en (

QVT)

, Reg

elsp

rach

en(P

RR)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

138

Reg

elsp

rach

en (

PRR)

...

Page 5: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Lite

ratu

r

[1]

War

mer

, J.

, Kle

ppe,

A.:

The

Obj

ect

Con

stra

int

Lang

uage

. Pr

ecis

e [

],

,pp

,j

gg

Mod

elin

gw

ith U

ML.

Add

ison

-Wes

ley,

19

99[2

] W

arm

er,

J.,

Kle

ppe,

A.:

The

Obj

ect

Con

stra

int

Lang

uage

Sec

ond

Editi

on.

Editi

on.

Get

ting

Your

Mod

els

Rea

dy F

or M

DA.

Add

ison

-Wes

ley,

20

03[3

] O

MG

UM

L sp

ecifi

catio

n,

ww

w.o

mg.

org/

tech

nolo

gy/d

ocum

ents

/

mod

elin

gsp

ecca

talo

g.ht

m#

UM

Lm

odel

ing_

spec

_cat

alog

.htm

#U

ML

[4]

OM

G O

CL,

htt

p://

ww

w.o

mg.

org/

spec

/OCL/

[5]

Wol

fgan

g Zus

eret

al:

Sof

twar

etec

hnol

ogie

für

Ein

stei

ger.

Vor

lesu

ngsu

nter

lage

für

die

Ver

anst

altu

ngen

ande

rTU

Dre

sden

Vor

lesu

ngsu

nter

lage

für

die

Ver

anst

altu

ngen

an

der

TU D

resd

en.

Pear

son

Stu

dium

, 20

09,

S.

145-

152

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

139

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1310

Page 6: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Con

stra

int

Def

init

ion

nac

h [

1]

–„A

con

stra

int

isa

rest

rict

ion

on o

neor

mor

eva

lues

of(p

art

of)

an o

bjec

t-or

ient

edm

odel

or

syst

em.“

In d

euts

chen

Leh

rbü

cher

n:

–Zus

iche

rung

–Ei

nsch

ränk

ung

–In

tegr

itäts

bedi

ngun

g–

Ran

dbed

ingu

ng

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1311

Inva

rian

te

Def

init

ion

–Ei

ne I

nva

rian

teis

t ei

n Con

stra

int,

das

für

ein

Obj

ekt

wäh

rend

sein

erga

nzen

Lebe

nsze

itw

ahr

sein

sollt

ew

ähre

nd s

eine

r ga

nzen

Leb

ensz

eit

wah

r se

in s

ollte

.

Syn

tax

context

<class

name>

inv

[<constraint

name>]: <OCL expression>

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1312

Page 7: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

OCL/

UM

L By

Exam

ple

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1313

Inva

rian

te -

Bei

spie

l

context

Meeting inv: self.end > self.start

--se

lfbe

zieh

t si

ch im

mer

auf

das

Obj

ekt,

für

das

das

Con

stra

int

bere

chne

tw

ird

Con

stra

int

bere

chne

t w

ird

Äq

uiv

alen

te F

orm

ulie

run

gen

tt

Mti

id

>t

tcontext

Meeting

inv: end

>start

context

Meeting

inv

startEndConstraint:

gself.end > self.start

--Ver

gabe

ein

es N

amen

s fü

r da

s Con

stra

int

•Sic

htba

rkei

ten

von

Att

ribu

ten

wer

den

durc

h O

CL

stan

dard

mäß

ig

igno

rier

t.

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1314

Page 8: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Prec

ondi

tion

(Vor

bedi

ngun

g)

•Pr

e-un

d Po

stco

nditi

ons

sind

Con

stra

ints

, di

e di

e Anw

endb

arke

it un

d di

e Aus

wirku

ng v

on O

pera

tione

n sp

ezifi

zier

en,

ohne

das

s da

für

ein

Alg

orith

mus

oder

eine

Impl

emen

tatio

nan

gege

ben

dafü

r ei

n Alg

orith

mus

ode

r ei

ne I

mpl

emen

tatio

nan

gege

ben

wird

.

Def

init

ion

Def

init

ion

–Ei

ne P

reco

nd

itio

nis

t ei

n Boo

lesc

her

Aus

druc

k, d

er z

um

Zei

tpun

kt d

es B

egin

ns d

er A

usfü

hrun

g de

r zu

gehö

rige

n O

pera

tion

wah

rse

inm

uss

Ope

ratio

n w

ahr

sein

mus

s.

Syn

tax

context

<class

name>::<operation> (<parameters>)

pre

[<constraint

name>]: <OCL expression>

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1315

Prec

ondi

tion

-Bei

spie

le

context

Meeting::shift(d:Integer)

pre: self.isConfirmed

= false

context

Meeting::shift(d:Integer)

pre:

d>0

pre:

d>0

context

Meeting::shift(d:Integer)

pre: self.isConfirmed

= false

and

d>0

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1316

Page 9: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Post

cond

ition

(Nac

hbed

ingu

ng)

Def

init

ion

–Ei

ne P

ost

con

dit

ion

ist

ein

Boo

lesc

her

Aus

druc

k, d

er

unm

ittel

bar

nach

der

Aus

führ

ung

der

zuge

hörige

nun

mitt

elba

r na

ch d

er A

usfü

hrun

g de

r zu

gehö

rige

n O

pera

tion

wah

r se

in m

uss.

Syn

tax

context

<class

name>::<operation> (<parameters>)

post

[<constraint

name>]:

<OCL

expression>

post

[<constraint

name>]:

<OCL

expression>

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1317

Post

cond

ition

-Bei

spie

le

context

Meeting::duration():Integer

post:

result

= self.end –

self.start

--re

sult

bezi

eht

sich

auf

den

Rüc

kkeh

rwer

t de

r O

pera

tion

context

Meeting::confirm()

context

Meeting::confirm()

post: self.isConfirmed

= true

context

Meeting::shift(d:Integer)

post: start

= start@pre

+d and

end = end@pre

+ d

--st

art@

pre

bezi

eht

sich

auf

den

Wer

tvo

rAus

führ

ung

der

star

t@pr

ebe

zieh

t si

ch a

uf d

en W

ert

vor

Aus

führ

ung

der

--O

pera

tion

--st

art

bezi

eht

sich

auf

den

Wer

t n

ach

Aus

führ

ung

der

Ope

ratio

n--

@pr

eis

t nu

r in

Pos

tcon

ditio

nser

laub

t

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1318

Page 10: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

OC

L-TY

PEN

UN

D

ÜO

CL-

AU

SD

CK

E

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1319

Bas

isty

pen

der

OCL-

Sta

ndar

dbib

lioth

ek

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1320

Page 11: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Sta

ndar

dope

ratio

nen

auf

Str

ings

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1321

Und

efin

iert

e W

erte

in O

CL

(Ocl

Voi

d)

•D

ie B

erec

hnun

g ei

nes

OCL-

Teila

usdr

ucke

s ka

nn u

.U.

zu e

inen

g

unde

finie

rten

Wer

t (O

clV

oid

) fü

hren

Ver

glei

chba

r m

it nu

llin

SQ

L od

er J

ava

•Te

stau

fun

defin

iert

enW

ert

mit

•Te

st a

uf u

ndef

inie

rten

Wer

t m

it

oclIsUndefined(): Boolean

--tr

uefa

lls d

as O

bjek

t un

defin

iert

(nu

ll)is

t,--

anso

nste

n fa

lse

•ty

pisc

her

Fall

des

Auf

tret

en u

ndef

inie

rter

Wer

te is

t de

r Zug

riff

auf ei

nen

nich

t ex

istie

rend

en A

ttribu

twer

t

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1322

Page 12: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Ung

ültig

e W

erte

in O

CL

(Ocl

Inva

lid)

•Ver

glei

chba

rm

itEx

cept

ions

in J

ava

–M

etho

dena

ufru

feau

f nu

llre

sulti

eren

in e

iner

Nul

lPoi

nter

-Ex

cept

ion

Exce

ptio

n.

•oclIsInvalid(): Boolean

--tr

uefa

lls d

as O

bjek

t un

gülti

g (i

nval

id)

ist,

--an

sons

ten

fals

ean

sons

ten

fals

e

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1323

Vie

rwer

tige

Logi

k in

OCL

2.3

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1324

Page 13: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Col

lect

ion

Type

s

Eige

nsch

afte

nIs

Ord

ered

not

IsO

rder

edEi

gens

chaf

ten

IsO

rder

edno

tIs

Ord

ered

IsU

niqu

eO

rder

edSet

Set

not

IsU

niqu

eSeq

uenc

eBag

not

IsU

niqu

eSeq

uenc

eBag

•Col

lect

ions

könn

en u

ndef

iner

teW

erte

(nu

ll),

aber

kei

ne

ungü

ltige

n W

erte

(in

valid

) en

thal

ten.

•Fa

llsei

neCol

lect

ion

eine

nun

gülti

gen

Wer

ten

thäl

t,w

ird

sie

Falls

ein

e Col

lect

ion

eine

n un

gülti

gen

Wer

t en

thäl

t, w

ird

sie

selb

er u

ngül

tig.

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1325

Nut

zerd

efin

iert

e Ty

pen

Mod

ellt

yp•

Nut

zerd

efin

iert

e Kla

sse

•Ei

ne K

lass

e be

sitz

t di

e fo

lgen

den

Feat

ure

s:–

Att

ribu

te(z

.B.start)

Att

ribu

te (

z.B. start)

–O

pera

tione

n (n

ur q

uery

oper

atio

ns)

(z.B

. duration())

duration())

–Kla

ssen

attr

ibut

e (z

.B.

Date::today)

Kla

ssen

oper

atio

nen

–Kla

ssen

oper

atio

nen

–Ass

ozia

tions

ende

n („

Nav

igat

ions

ausd

rück

e“)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1326

Page 14: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

OCL-

Kon

form

itäts

rege

lng

OCL

ist

eine

typ

sich

ere

Spr

ache

.D

er P

arse

r pr

üft

OCL-

Aus

drüc

ke a

uf K

onfo

rmitä

t:•

Typ

1 is

t ko

nfor

m z

u Ty

p 2,

wen

n ei

ne I

nsta

nz v

on T

yp 1

an

jede

rSte

lleer

setz

tw

erde

nka

nnw

oei

neIn

stan

zvo

man

jed

er S

telle

ers

etzt

wer

den

kann

, w

o ei

ne I

nsta

nz v

om

Typ

2 er

war

tet

wird.

Allg

emei

ne R

egel

n •

Typ

1 is

t ko

nfor

m z

u Ty

p 2,

wen

n Sie

iden

tisch

sin

d.J

dT

it

kf

jd

iS

t•

Jede

r Ty

p is

t ko

nfor

mzu

jed

emse

iner

Sup

erty

pen.

•Ty

pkon

form

ität

ist

tran

sitiv

.

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1327

OCL

Con

stra

ints

und

Ver

erbu

ngC

onst

rain

tsal

lgem

ein

•Con

stra

ints

eine

r Sup

erkl

asse

wer

den

von

den

Sub

klas

sen

geer

bt.

Inva

rian

ten

•Ei

ne S

ubkl

asse

kan

n di

e In

varian

te v

erst

ärke

n, s

ie a

ber

nich

t ab

schw

äche

n.ab

schw

äche

n.

Pre

con

dit

ion

s•

Eine

Vor

bedi

ngun

gka

nnbe

iein

emÜ

bers

chre

iben

eine

rO

pera

tion

Eine

Vor

bedi

ngun

g ka

nn b

ei e

inem

Übe

rsch

reib

en e

iner

Ope

ratio

n ei

ner

Sub

klas

se a

ufge

wei

cht,

abe

r ni

cht

vers

tärk

t w

erde

n.

Pos

tcon

dit

ion

sos

tco

dt

os

•Ei

ne N

achb

edin

gung

kan

n be

i ein

em Ü

bers

chre

iben

ein

er O

pera

tion

eine

r Sub

klas

se v

erst

ärkt

, ab

er n

icht

auf

gew

eich

t w

erde

n.

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1328

Page 15: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Nav

igat

ions

ausd

rück

e

•Ass

ozia

tions

ende

n (R

olle

nnam

en)

könn

en v

erw

ende

t w

erde

n, u

m

von

eine

m O

bjec

tim

Mod

ell/

Sys

tem

zu

eine

m a

nder

en z

u na

vigi

eren

(Nav

igat

ion

)g

(g

)•

Nav

igat

ione

nw

erde

n in

OCL

als

Att

ribu

te b

ehan

delt

(dot

-N

otat

ion)

.•

Der

Typ

eine

rN

avig

atio

nis

ten

twed

er•

Der

Typ

ein

er N

avig

atio

n is

t en

twed

er–

Nu

tzer

def

inie

rter

Typ

(Ass

ozia

tions

ende

mit

Mul

tipliz

ität

max

imal

1)

Kol

lekt

ion

von

nutz

erde

finie

rten

Type

n(A

ssoz

iatio

nsen

de–

Kol

lekt

ion

von

nutz

erde

finie

rten

Typ

en (

Ass

ozia

tions

ende

m

it M

ultip

lizitä

t>

1)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1329

Nav

igat

ions

ausd

rück

e -

Bei

spie

le

Nu

tzer

def

inie

rter

Typ

z.B.moderator

Nav

igat

ion

von Meeting:

TypTeammember

gg

yp

context

Meeting

ilf

dt

dG

df

linv:

self.moderator.gender

=Gender::female

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1330

Page 16: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Nav

igat

ions

ausd

rück

e -

Bei

spie

le

Col

lect

ion

Col

lect

ion

–z.

B. participants

Nav

igat

ion

von Meeting

ist

vom

Typ

Set(Teammember)

–O

pera

tione

nau

fCol

lect

ions

wer

den

inde

rPf

eiln

otat

ion“

(->

)O

pera

tione

n au

f Col

lect

ions

wer

den

in d

er „

Pfei

lnot

atio

n (

>)

gesc

hrie

ben

–Kur

znot

atio

n fü

r di

e collect–O

pera

tion

ist

die

dot-

Not

atio

n

(für

self->collect(participants)

bess

er(

(p

p)

self.participants)

context

Meetingg

inv:

self->collect(participants)->size()>=2

tt

Mti

ilf

ti

it

>i

()>

2D

r. B

irgi

t D

emut

hSW

T II

, W

S 2

012/

1331

context

Meeting

inv:

self.participants->size()>=2

Ope

ratio

nen

auf

Col

lect

ions

(1)

•22

Ope

ratio

nen

mit

unte

rsch

iedl

iche

r Sem

antik

in A

bhän

gigk

eit

vom

Col

lect

ion-

Typ,

z.B

.V

li

hti

()

–Ver

glei

chso

pera

tione

n(=, <>)

–Kon

vert

ieru

ngso

pera

tione

n (asBag(), asSet(),

asOrderedSet(), asSequence())

–Ver

schi

eden

e in

clud

ing-

und

excl

udin

g-O

pera

tione

n–

Ope

ratio

n flatten()

erze

ugt

aus

eine

r Kol

lekt

ion

von

Kol

lekt

ione

n ei

ne K

olle

ktio

n m

it ei

nzel

nen

Ob j

ekte

n, z

.B.

j,

Set{Bag{1,2,2},Bag{2}}

�Set{1,2}

–M

enge

nope

ratio

nen

(unionintersectionminussymmetricDifference)

(union,intersection,minus,symmetricDifference)

–O

pera

tione

n au

f so

rtie

rten

Kol

lekt

ione

n (z

.B. first(),

last(), indexOf())

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1332

Page 17: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Ope

ratio

nite

rate

()O

pera

tion

itera

te()

Collection->iterate( element

: Type1;

result

:Type2

=<expression>

result

:Type2

=<expression>

| <expression

with

element

and

result> }

•Alle

and

eren

iter

iere

nden

Ope

ratio

nen

sind

ein

Spe

zial

fall

von

itera

te()

und

kön

nen

dam

it au

sged

rück

t w

erde

n, z

.B.

Set {1,2,3}->sum() du

rch

St{1

23}

>Set{1,2,3}->

iterate{i: Integer, sum: Integer=0 | sum

+ i }

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1333

Ope

ratio

nen

auf

Col

lect

ions

(2)

p(

)

Vor

def

inie

rte

Iter

ator

enau

f al

len

Col

lect

ion-

Type

n, z

.B.

any(expr)

any(expr)

collect(expr)

exists(expr)

forAll(expr)

isUnique(expr)

one(expr)

select(expr)

reject(expr)

reject(expr)

sortedBy(expr)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1334

Page 18: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Wei

tere

Bei

spie

le f

ür C

olle

ctio

n-O

pera

tione

n (1

)

•Ei

nTe

amm

eetin

gm

uss

für

ein

ganz

esTe

amor

gani

sier

tEi

n Te

amm

eetin

g m

uss

für

ein

ganz

es T

eam

org

anis

iert

w

erde

n (O

pera

tion forAll()):

icontext

Teammeeting

inv:

participants->forAll(team=self.for)

context

Meeting inv: oclIsTypeOf(Teammeeting)

implies

participants->forAll(team=self.for)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1335

Wei

tere

Bei

spie

le f

ür C

olle

ctio

n-O

pera

tione

n (2

)

•W

eite

re N

achb

edin

gung

en(O

pera

tionselect()):

gg

(p

())

context

Teammember::numMeeting():Integer

post: result=meetings->size()

context

Teammember::numConfMeeting():Integer

context

Teammember::numConfMeeting():Integer

post:

result=meetings->select(isConfirmed)->size()

g(

)()

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1336

Page 19: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

allIns

tanc

es()

-Ope

ratio

n

•Er

laub

t fü

r –

Nut

zerd

efin

iert

eTy

pen

erla

ubt

zB

–N

utze

rdef

inie

rte

Type

n er

laub

t, z

.B.

Person.allInstances()

–Boo

lean

, O

CLV

oid

und

OCLI

nval

id

•Fü

r un

endl

iche

Men

gen

von

Type

n ni

cht

erla

ubt,

z.B

. Integer

allInstances()

Integer.allInstances()

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1337

Teila

usdr

ücke

in O

CL

(let

)(

)

•In

tere

ssan

t in

kom

plex

en O

CL-

Aus

drüc

ken

•Ei

n le

t-Aus

druc

k de

finie

rt e

ine

Var

iabl

e (z

.B. noConflict),

die

an

stel

le e

ines

Tei

laus

druc

kes

benu

tzt

wer

den

kann

.

Bei

s pie

lp context

Meeting inv:

let

noConflict

: Boolean =

participants.meetings->forAll

(m|m<>self

and

m.isConfirmed

implies

not

self

inConflict(m))

not

self.inConflict(m))

in

isConfirmed

implies

noConflict

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1338

Page 20: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

WEI

TER

EO

CL-

AN

WEI

SU

NG

EN

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1339

OCL-

Met

amod

ell a

us p

ragm

atis

cher

Sic

ht

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1340

Page 21: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Wie

derv

erw

endb

are

Aus

drüc

ke (

Def

initi

on)

()

•D

efin

ition

von

Att

ribu

ten

und

Anf

rage

oper

atio

nen

•Ver

wen

dung

wie

nor

mal

e Att

ribu

te u

nd O

pera

tione

n•

Syn

tax

ist

ähnl

ich

dem

let-

Aus

druc

k•

Ged

acht

für

die

Wie

derv

erw

endu

n g v

on O

CL-

Teila

usdr

ücke

n in

g

vers

chie

den

enCon

stra

ints

context

Meetingg

def: noConflict

: Boolean =

participants.meetings->forAll(m|m<>self

dand

m.isConfirmed

implies

not

self

inConflict(m))

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1341

self.inConflict(m))

Anf

rage

oper

atio

nen

(Ope

ratio

n Bod

y)

•Spe

zifik

atio

n vo

n O

pera

tione

n oh

ne S

eite

neff

ekte

(d.

h.

Ope

ratio

nen,

die

nic

ht d

en Z

usta

nd ir

gend

eine

s O

bjek

tes

im

Sys

tem

änd

ern)

y)

•Vol

le A

usdr

ucks

kraf

t ei

ner

Anf

rage

spra

che

(ver

glei

chba

r m

it SQ

L)

Bei

spie

l

context

context

Teammember::getMeetingTitles(): Bag(String)

body:

meetings->collect(title)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1342

Page 22: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Tran

sitiv

e H

ülle

•W

ird

sehr

oft

ben

ötig

t •

Neu

in O

CL

2.3

–Tr

ansi

tive

Clo

sure

-Ope

rato

r cl

osur

e()

–D

efin

iert

als

Ite

rato

rsource->closure(expression)

(p

)

•Pr

oble

m is

t ef

fizie

nte

Impl

emen

tatio

n

ttP

llD

dt()St(P

)contextPerson::allDescendants():Set(Person)

body: self.parents-> closure(children)

contextPerson::allAnchestors():Set(Person)

body: self->OrderedSet()->closure(parents)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1343

Anf

angs

wer

te (

Initi

al V

alue

)

Bi

il

Bei

spie

le

context

Meeting::isConfirmed

: Boolean

ginit: false

context

Teammember:meetings

:Set(Meetings)

context

Teammember:meetings

:Set(Meetings)

init: Set{}

•M

an b

each

te d

en U

nter

schi

ed z

u In

varian

ten

und

Abl

eitu

ngsr

egel

n: E

in A

nfan

gsw

ert

mus

s nu

r zu

m Z

eitp

unkt

de

r Er

zeug

ung

des

Obj

ekte

s ge

lten!

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1344

Page 23: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Abg

elei

tete

Att

ribu

te u

nd A

ssoz

iatio

nen

(Di

dV

l)

(Der

ived

Val

ue)

•Bei

spie

lfür

ein

abg

elei

tete

sA

ttri

bu

t(s

ize)

Bei

spie

l für

ein

ab

gel

eite

tes

Att

rib

ut

(si

ze)

context

Team::size:Integer

derive:members->size()

derive:members->size()

•Bei

spie

l für

ein

e ab

gel

eite

te A

ssoz

iati

on–

conf

lict

defin

iert

mite

inan

der

(zei

tlich

) in

Kon

flikt

st

ehen

de M

eetin

gs

context

Meeting::conflict:Set(Meeting)

derive: select(m|m<>self

and

lf

iC

fli

t(

))

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1345

self.inConflict(m))

Zus

amm

enfa

ssun

g vo

n O

CL-

Anw

eisu

ngen

zu

Pack

ages

zuPa

ckag

es

package

MeetingExample

context

Meeting::isConfirmed

: Boolean

init:

false

init:

false

context

Teammember:meetings

: Set(Meetings)

init: Set{}

..

..

endpackage

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1346

Page 24: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

AN

WEN

DU

NG

SFÄ

LLE

ÜFÜR

OC

L

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1347

OCL

in w

eite

ren

Mod

elle

n

•Zus

tand

sdia

gram

m (

Gua

rds,

Pre

-un

d Po

st-C

ondi

tions

)•

Seq

uenz

diag

ram

m•

Seq

uenz

diag

ram

m•

Akt

ivitä

tsdi

agra

mm

•Anw

endu

n gsf

alld

iagr

amm

gg

•Kom

pone

nten

diag

ram

m

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1348

Page 25: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

oclInS

tate

()•

vord

efin

iert

es P

rädi

kat

für

alle

Obj

ekte

(Ty

p OclAny)

oclInState(s:

OclState)

:Boolean

oclInState(s:

OclState)

:Boolean

context

Vector::removeElement(d:Data)

pre: oclInState(notEmpty)

post:

size@pre

= 1 implies

oclInState(empty)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1349

pp

pp

y

Typi

sche

Anw

endu

ngsf

älle

für

OCL

MO

F-M

odel

leb

ene

Bei

spie

le f

ür

die

Ver

wen

du

ng

von

OC

L

Met

amod

elle

:{M

OF-

, Ec

ore-

basi

ert}

X {

UM

L, C

WM

, O

DM

, SBVR,

PRR,

nutz

erde

finie

rte

DSLs

, …

}

MO

FM

odel

leb

ene

Bei

spie

le f

ür

die

Ver

wen

du

ng

von

OC

L

M2

(M

etam

od

ell)

•Spe

zifik

atio

n vo

n W

ell-

Form

edn

ess

Ru

les

(WFR

s)in

OM

G-

Sta

ndar

ds•D

efin

ition

von

Mod

ellie

rung

sric

htlin

ien

für

DS

Ls (

Dom

ain

Sp

ecif

icLa

ng

uag

es)

•Spe

zifik

atio

n vo

n M

odel

lab

bild

un

gen

M1

(Mo

del

l)•Ü

berp

rüfu

ngde

rKo

nsis

tenz

von

Mod

elle

nm

itde

mM

etam

odel

lM

1 (

Mo

del

l)•Ü

berp

rüfu

ng d

er K

onsi

sten

z vo

n M

odel

len

mit

dem

Met

amod

ell

(�CASE-

Tool

)•E

valu

atio

n vo

n M

odel

lieru

ngsr

icht

linie

n in

DSL-

Inst

anze

n•A

usfü

hrun

g vo

n M

odel

labb

ildun

gen

•Spe

zifik

atio

n vo

n G

esch

äfts

reg

eln

/C

onst

rain

ts•S

pezi

fikat

ion

von

Test

fälle

n

M0

(O

bje

kte)

•Eva

luat

ion

von

Ges

chäf

tsre

geln

/Con

stra

ints

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1350

•Aus

führ

ung

von

Test

fälle

n

Page 26: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Bei

spie

le f

ür O

CL

auf

der

Met

amod

elle

bene

•W

FR im

UM

L-M

etam

odel

l

context

GeneralizableElement

inv:

not self.allParents->includes(self)

()

--

Zyk

len

in d

er V

erer

bung

shie

rarc

hie

sind

nic

ht e

rlau

bt

•U

ML

Mod

ellie

rung

sric

htlin

ie/T

eile

ines

UM

LPr

ofil

bzw

eine

r•

UM

L M

odel

lieru

ngsr

icht

linie

/Tei

l ein

es U

ML-

Prof

il bz

w.

eine

r D

SL

tt

Cl

ifi

iSi

lI

hit

context

Classifier

inv

SingleInheritance:

self.generalization->size()<= 1

--

Java

-spe

zifis

ch:

kein

meh

rfac

he V

erer

bung

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1351

Jaa

spe

sce

eac

ee

ebu

g

OC

L TO

OLS

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1352

Page 27: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Dre

sden

OCL

(dre

sden

-ocl

.org

/)

Lars

Sch

ütze

RM

Ron

ny M

arx

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1353

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1354

Page 28: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1355

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1356

Page 29: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

XM

I/U

ML

Impo

rt f

ür D

resd

en O

CL

•To

pCas

ed(E

MF

UM

L2 X

MI)

•M

agic

Dra

w (

EMF

UM

L2 X

MI)

ld

()

•Vis

ual P

arad

igm

(EM

F U

ML2

XM

I)•

Eclip

seU

ML2

/ U

ML2

Too

ls (

EMF

UM

L2 X

MI)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1357

Eini

ge w

eite

re U

ML/

OCL

Tool

s

•M

agic

Dra

wEn

terp

rise

Edi

tion

v17

(mit

Dre

sden

OCL2

Too

lkit

�)

–Ev

alua

tions

-Liz

enz

•Bor

land

Tog

eth

er20

08 (

OCL/

QVT)

•Ec

lipse

MD

T/O

CL

for

Ecor

eBas

edM

odel

sF

ifü

b–

Frei

verf

ügba

r

•U

se(U

nive

rsitä

t Bre

men

)Fr

eive

rfüg

bar

–Fr

ei v

erfü

gbar

–Ani

mat

ion,

seh

r sc

hön

geei

gnet

für

Leh

rzw

ecke

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1358

Page 30: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

OCL

Sup

port

in M

agic

Dra

w E

nter

pris

e Ed

ition

“OCL

valid

atio

n ru

les”

1S

ifik

tif

UM

LM

tkl

(M2)

/V

ifik

tiU

ML

1.Spe

zifik

atio

nau

f U

ML

Met

akla

ssen

(M2)

/ V

erifi

katio

nvo

n U

ML-

Mod

elle

n(M

1)

2Spe

zifik

atio

nvo

nSte

reot

ypen

(M2)

/Ver

ifika

tion

von

UM

L2.

Spe

zifik

atio

nvo

nSte

reot

ypen

(M2)

/ V

erifi

katio

nvo

n U

ML-

Mod

elle

n(M

1)

3Spe

zifik

atio

nau

fU

ML-

Mod

elle

n(M

1)/

Ver

ifika

tion

von

UM

L-3.

Spe

zifik

atio

nau

f U

ML-

Mod

elle

n(M

1) /

Ver

ifika

tion

von

UM

L-In

stan

zen

(Obj

ekte

n)

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1359

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1360

Page 31: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1361

Form

ale

Ver

ifika

tion

von

OCL-

Con

stra

ints

•Fü

r in

kon

sist

ente

Spe

zifik

atio

nen

(Kom

bina

tion

von

Con

stra

ints

die

sich

wid

ersp

rech

en)

gibt

esw

enig

Con

stra

ints

, di

e si

ch w

ider

spre

chen

) gi

bt e

s w

enig

U

nter

stüt

zung

, di

ese

aufz

ufin

den.

–U

MLt

oCSP

(Tra

nsfo

rmat

ion

eine

s U

ML/

OCL-

Mod

els

in e

in

Con

stra

int

Sat

isfa

ctio

nPr

oble

m(C

SP)

)Jo

rdiC

abot

etal

Con

stra

int

Sat

isfa

ctio

nPr

oble

m(C

SP)

), J

ordi

Cab

ot e

t al

•ht

tp:/

/gre

s.uo

c.ed

u/U

MLt

oCSP/

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1362

Page 32: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

The

OCL

Tool

Lan

dsca

pe

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

13Fo

lie 6

3

A F

eatu

re M

odel

for

an I

DE4

OCL

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

13Fo

lie 6

4

Page 33: Einführung in OCL (Object Constraint Language)st.inf.tu-dresden.de/files/teaching/ws11/st2/slides/13-model... · Dr. Birgit Demuth SWT II, WS 2012/13 38. WEITERE OCL-ANWEISUNGEN

Kt

ktK

on

takt

:bi

rgit.

dem

uth@

tu-d

resd

en.d

eht

tp:/

/dre

sden

-ocl

.org

/ht

tp:/

/dre

sden

ocl.o

rg/

FRA

GEN

?IN

TER

ESS

E A

N D

A/

BA

/G

B?

Dr.

Birgi

t D

emut

hSW

T II

, W

S 2

012/

1365


Recommended