OCL Slide Share

Embed Size (px)

Citation preview

  • 8/13/2019 OCL Slide Share

    1/118

    Jordi Cabot AtlanMod / EMN / INRIA /LINA/Martin Gogolla University of Breen

    !"it# t#e inval$able #el% of slides of t#e BiG gro$% & 'U(ien)

    #tt%*//odeling&lang$ages+,o

    -softodeling

    .be,t Constraint Lang$ageA definitive g$ide

    1 AtlanMod --

    http://modeling-languages.com/http://modeling-languages.com/
  • 8/13/2019 OCL Slide Share

    2/118

  • 8/13/2019 OCL Slide Share

    3/118

    Why ocl?

    3

  • 8/13/2019 OCL Slide Share

    4/118

    (#y .CL

    No serious use of UML

    without OCL!!! (limited

    expressiveness of ALL

    (graphical) notations

  • 8/13/2019 OCL Slide Share

    5/118

    (#at does t#e odel N.' say

  • 8/13/2019 OCL Slide Share

    6/118

    .CL is every"#ere

    (#ere ,an "e find .CL1

    Constraints

    (ell&foredness r$les

    2erivation r$les 3re/%os,onditions

    G$ards

    Model to odel transforations Model to te0t transforations

  • 8/13/2019 OCL Slide Share

    7/118

    (#y .CL

    Natural language is

    clearl not enough

  • 8/13/2019 OCL Slide Share

    8/118

    Motivation Example 1

    Employee

    age: Integer

    age > =18

    Please nounderagedemployees!

    alter = 21

    e3:Employeee1:Employee

    age = 17

    e2:Employee

    age = 37

  • 8/13/2019 OCL Slide Share

    9/118

    (#y .CL & Alternatives to .CL

    NL

    4.L

    Alloy

    56L

    25Ls for s%e,ifi, b$siness r$le %atterns

    7is$al .CL

    5B7R

    ot#ers1

    8o$ ay not li9e it b$t rig#t no" t#ere is not#ing better t#an.CL:: !and so tig#tly integreated already "it# t#e ot#ere0isting odeling standards)

  • 8/13/2019 OCL Slide Share

    10/118

    (#y .CL 7is$al .CL

    VSContext Person inv:

    self.isMarried implies(self.wife.age>=18 or

    self.!s"and.age>=18#

  • 8/13/2019 OCL Slide Share

    11/118

    (#y .CL & 5B7R

    ;ea,# %rod$,t belongs to e0a,tly < faily= is defined as*

    The rule is a proposition meant by a necessity formulation.

    . .The necessity formulation embeds a universal quantification, u1.

    (3) . . . The universal quantification, u1, introduces a first variable, v1.

    (4) . . . . The variable v1 ranges over the concept product.

    (!) . . . The universal quantification, u1, scopes over an e"actly one quantification, e1.

    (#) . . . . The e"actly one quantification, e1, introduces a second variable, v$.

    (%) . . . . . The variable, v$, ranges over the concept family.

    (&) . . . . The e"actly one quantification, e1, scopes over an atomic formulation, a1.

    (') . . . . . The atomic formulation, a1, is based on the fact type product belongs to family.

    (1) . . . . . The atomic formulation, a1, has the first role binding.

    (11) . . . . . . The first role binding is of the role product.

    (1$) . . . . . . The first role binding binds to the variable v1.

    (13) . . . . . The atomic formulation has the second role binding.

    (14) . . . . . . The second role binding is of the role family. (1!) . . . . . . The second role binding binds to the variable v$.

  • 8/13/2019 OCL Slide Share

    12/118

    The Language

    12

  • 8/13/2019 OCL Slide Share

    13/118

    .CL* Basi, Con,e%ts

    .CL is a ri,# lang$age t#at offers %redefined e,#aniss for*

    $ Retrieving t#e val$es of an obe,t

    $ Navigating t#ro$g# a set of related obe,ts>

    $ Iterating over ,olle,tions of obe,ts !e+g+> forAll> e0ists> sele,t)

    .CL in,l$des a %redefined standard library* set of ty%es ? o%erationson t#e

    $ 3riitive ty%es* Integer> Real> Boolean and 5tring

    $ Colle,tion ty%es* 5et> Bag> .rdered5et and 5e@$en,e

    $ E0a%les of o%erations* and> or> not !Boolean)> ?> > > > !Real

    and Integer)> $nion> siDe> in,l$des> ,o$nt and s$ !5et)+

  • 8/13/2019 OCL Slide Share

    14/118

    5oe first e0a%les

  • 8/13/2019 OCL Slide Share

    15/118

    5oe first e0a%les

    ,onte0t 6$ote inv .verero* self+val$e F

    ,onte0t Bla,9Listed inv NoRentalsBla,9Listed*self+rental&forAll!r r+start2ate self+bla,9Listed2ate)

    ,onte0t C$stoer**%rei$* boolean init* false

  • 8/13/2019 OCL Slide Share

    16/118

    5oe first e0a%les

    ,onte0t C$stoer**dis,o$nt* integer

    derive*

    if not self+%rei$ t#en

    if self+rental+,ar+,arGro$%&

    sele,t!,,+,ategoryH=#ig#=)&siDe!)H

    t#en

  • 8/13/2019 OCL Slide Share

    17/118

    5oe first e0a%les

    ,onte0t Car**ost3o%$lar!)* boolean

    body*

    Car**allInstan,es!)&forAll!,

  • 8/13/2019 OCL Slide Share

    18/118

    5oe first e0a%les

    ,onte0t Rental**ne"Rental!id*Integer> %ri,e*Real>starting2ate*2ate> ending2ate*2ate> ,$stoer*C$stoer>,arRegN$*5tring> %i,9$%Bran,#* Bran,#> dro%.ffBran,#* Bran,#)

    %re* ,$stoer+li,enseE0%2ateending2ate

    %ost* Rental+allInstan,es&one!r

    r+o,lIsNe"!) and r+o,lIs'y%e.f!Rental) and

    r+ending2ateHending2ate and r+starting2ateHstarting2ate and

    r+driverH,$stoer and r+%i,9$%Bran,#H%i,9$%Bran,# and

    r+dro%.ffBran,#Hdro%.ffBran,# and

    r+,arHCar+allInstan,es!)&any!, ,+regN$H,arRegN$))

  • 8/13/2019 OCL Slide Share

    19/118

    Lang$age synta0* ,onte0t

    A ,onte0t #as to be assigned to ea,# .CL&stateent$ Starting address "#i,# odel eleent is t#e .CL&stateent defined for

    $ 5%e,ifies "#i,# odel eleents ,an be rea,#ed $sing %at# e0%ressions

    '#e ,onte0t is s%e,ified by t#e 9ey"ord contextfollo"ed by t#e naeof t#e odel eleent !ostly ,lass naes)

    '#e 9ey"ord selfs%e,ifies t#e ,$rrent instan,e> "#i,# "ill beeval$ated by t#e invariant !,onte0t instan,e)+$ self,an be oitted if t#e ,onte0t instan,e is $ni@$e

    Employee

    age: Integer

    contextEmploeeinv: self!age > 18

    contextEmploeeinv: age > 18

    =

  • 8/13/2019 OCL Slide Share

    20/118

    Lang$age synta0* navigation

    Conte0t instan,e

    $ context Person

    A,,essing attrib$tes

    $ self.age

    Calling o%erations

    $ .%erations $st not #ave side effects

    $ self.getAge()

    Asso,iation ends

    $ Navigate to t#e o%%osite asso,iation end $sing role naesself.employer Ret$rn val$e is of ty%e Company

    $ Navigation often res$lts into a set of obe,ts E0a%lecontext Company

    self.employees Ret$rn val$e is of ty%e Set (Person)

    Person

    age : intgetAge"# : int$etAge"#

    Companyemploee

    $emploer

    % 1

    hat does c"emploees"emploer return#

  • 8/13/2019 OCL Slide Share

    21/118

    E0a%le

  • 8/13/2019 OCL Slide Share

    22/118

    E0a%le

  • 8/13/2019 OCL Slide Share

    23/118

    .CL 'y%es !MM 7ie")

    OCLType

    /plepe

    ModelElementpeDataType

    PrimitiveTypeCollectionType

    Anpeoidpe

    ,tring oolean Integer 5eal

    6rdered,etpe ,e/en*epe agpe ,etpe

  • 8/13/2019 OCL Slide Share

    24/118

    .CL 'y%es !A feat$re odel vie")

    . f / d f d

  • 8/13/2019 OCL Slide Share

    25/118

    .%erations for %riitive/%redefinedty%es

    Note that an OrderedSet is not a Set!

    . i f i i i / d fi d

  • 8/13/2019 OCL Slide Share

    26/118

    .%erations for %riitive/%redefinedty%es

    Simple type Predefined operations

    Integer %' ' ' .' a$"#' ;

    5eal %' ' ' .' loor"#' ;

    oolean and' or' xor' not' implie$

    ,tring *on*at"#' $i

  • 8/13/2019 OCL Slide Share

    27/118

    .%erations for .,lAny

    Operation Eplanation of result

    =(obj2:OclAny):Boolean r/e' i obj2and objreeren*e te $ame o)e*t

    oclIsTypeOf(type:OclType):Boolean

    oclIsin!Of(type:OclType): Boolean

    oclAsType(type:Ocltype):

    Type

    e re$/lt i$ obj o tpe type' or #n!efine!' i te

    */rrent tpe o obji$ not typeor a dire*t orindire*t $/tpe o it "*a$ting#!

    *cl+ny& Supertypeof all %riitive ty%es

    $ Operations are inheritedby all ot#er ty%es+

    Operations of*cl+ny!e0tra,t)

    $ Re,eiving obe,t is denoted by ob

  • 8/13/2019 OCL Slide Share

    28/118

    .%erations for .,lAny

    oclIsKindOf vs. oclIsTypeOf

    Person

    Student Professor

    ,onte0t Person

    self+o,lIsOind.f!3erson) * true

    self+o,lIs'y%e.f!3erson) * true

    self+o,lIsOind.f!5t$dent) *false

    self+o,lIs'y%e.f!5t$dent) *false

    ,onte0t Student

    self+o,lIsOind.f!3erson) * true

    self+o,lIs'y%e.f!3erson) * false

    self+o,lIsOind.f!5t$dent) * true

    self+o,lIs'y%e.f!5t$dent) * true

    self+o,lIsOind.f!3rofessor) * false

    self+o,lIs'y%e.f!3rofessor) * false

    Can you guess the difference?

  • 8/13/2019 OCL Slide Share

    29/118

    .CL7oid

    .CL7oid in,l$des t#e n$ll val$e !and t#ereforeall s$%erty%es of .CL7oid)

    E0a%lesn$ll*.CL7oid

    ada+dis,o$ntHn$ll * Booleanbran,#+addressHn$ll * Boolean

    n$llQ * 5et!5tring)

  • 8/13/2019 OCL Slide Share

    30/118

    &val$ed logi, for .CL

    b not!b) &&&&&&?&&&&&&& n$ll n$ll false tr$e tr$e false

    b bb< or b n$ll false tr$e b< and b n$ll false tr$e&&&&&&&&&?&&&&&&&&&&&&&&&&& &&&&&&&&&&?&&&&&&&&&&&&&&&&&&

    n$ll n$ll n$ll tr$e n$ll n$ll false n$llb< false n$ll false tr$e b< false false false false tr$e tr$e tr$e tr$e tr$e n$ll false tr$e

    b bb< 0or b n$ll false tr$e b< i%lies b n$ll false tr$e&&&&&&&&&&?&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&?&&&&&&&&&&&&&&&&&& n$ll n$ll n$ll n$ll n$ll n$ll n$ll tr$e

    b< false n$ll false tr$e b< false tr$e tr$e tr$e tr$e n$ll tr$e false tr$e n$ll false tr$e

    b b b< H b n$ll false tr$e b< b n$ll false tr$e&&&&&&&&&&?&&&&&&&&&&&&&&&&&& &&&&&&&&&?&&&&&&&&&&&&&&&&&& n$ll tr$e false false n$ll false tr$e tr$eb< false false tr$e false b< false tr$e false tr$e

    tr$e false false tr$e tr$e tr$e tr$e false

  • 8/13/2019 OCL Slide Share

    31/118

    .%erations for ,olle,tions

    Operation Eplanation of result

    si$e():Inte%er ?/mer o element$ in coll

    incl#!es(obj:OclAny):Boolean

    r/e' i objexi$t$ in coll

    is&mpty:Boolean r/e' i coll*ontain$ no element$

    s#m:T,/m o all element$ in collElement$ ave to e o tpe Integer or 5eal

    Colle,tion is an a!stract supertype for all set ty%es

    $ 5%e,ifi,ation of t#e mutual o%erations

    $-et, ag, -equence, *rdered-et in#erit t#ese o%erations "aution# .%erations "it# a ret$rn val$e of a set&val$ed ty%e ,reate a ne" ,olle,tion !no side effe,ts)

    5ynta0* v & o%!) E0a%le* P > Q & siDe!)

  • 8/13/2019 OCL Slide Share

    32/118

    .%erationen for 5et/Bag

    Operation Eplanation of result

    #nion(set2:'et(T)):'et(T) @nion o set and set2

    intersection(set2:'et(T)):'et(T)

    Inter$e*tion o setand set2

    !ifference(set2:'et(T)):'et() ieren*e $etB element$ o set' Ci* do not *on$i$tin set2

    symmetricDifference(set2:'et(T)):'et(T)

    ,et o all element$' Ci* are eiter in setor in set2'/t do not exi$t in ot $et$ at te $ame time

    -etand agdefine additional o%erations$ Generally based on theory of set concepts

    Operations ofSet!e0tra,t)$ Re,eiving obe,t is denoted by set

    Operations of $ag!e0tra,t)

    Operation Eplanation of result

    #nion(ba%2:Ba%(T)):Ba%(T) @nion o ba%and ba%2

    intersection(ba%2:Ba%(T)): Ba%(T) Inter$e*tion o ba%and ba%2

    A%

    BA

    AD DA

  • 8/13/2019 OCL Slide Share

    33/118

    .%erations for .rdered5et/5e@$en,e

    Operation Eplanation of result

    first:T ir$t element o or!ere!'et

    last:T Fa$t element o or!ere!'et

    at(i:Inte%er):T Element on index i o or!ere!'ets#bOr!ere!'et(loer:Inte%er#pper:Inte%er):Or!ere!'et(T)

    ,/$et o or!ere!'etall element$ o or!ere!'etin*l/ding te element on po$itionloer and teelement on po$ition #pper

    insertAt(in!e*:Inte%erobject5e$/lt i$ a *op o te or!ere!'et' in*l/ding te

    *rdered-etand -equencesdefine additional o%erations

    $ Allo" a,,ess or odifi,ation t#ro$g# an %nde

    Operations of OrderedSet!e0tra,t)$ Re,eiving obe,t is denoted by ordered-et

    Operations of Se&uence$ Analogo$s to t#e o%erations of .rdered5et

    F < n

  • 8/13/2019 OCL Slide Share

    34/118

    Iterator&based o%erations

    .CL defines o%erations for /ollections$sing 0terators

    $ Pro'ection of ne" /ollectionso$t of e0isting ones

    $ Co%a,t declaratie specification instead of i%erative algorit#s

    3redefined .%erations

    $ sele,t!e0%) * /ollection

    $ ree,t!e0%) * /ollection

    $ ,olle,t!e0%) * /ollection

    $ forAll!e0%) * oolean

    $ e0ists!e0%) * oolean

    $ isUni@$e!e0%) * oolean

    iterate!) Iterate over all eleents of a /ollection

    $ Generi, o%eration

    $ 3redefined o%erations are defined "it# iterate!)

  • 8/13/2019 OCL Slide Share

    35/118

    5ele,t / Ree,t

    Selectand e'ect ret$rn s$bsets of ,olle,tions

    $ Iterate over t#e ,o%lete ,olle,tion and ,olle,t eleents 5ele,t

    $ esult* 5$bset of ,olle,tion> in,l$ding eleents "#ereboolean"pristrue

    Ree,t

    $ esult* 5$bset of ,olle,tion> in,l$ding eleents "#ere

    boolean"prisfalse

    collection +, select( v : Type - boolean&*p(v) )collection +, select( v - boolean&*p(v) )collection +, select( boolean&*p )

    collection+, reject(v : Type - boolean&*p(v))

    $o we need a re%ect operation#

  • 8/13/2019 OCL Slide Share

    36/118

    5ele,t o%eration

    *ontext Gompan inv: $el!emploee > $ele*t"e : Emploee H e!age>0# >notEmpt"#

    Fi$t per$on$&er$on> = neC Fi$t"#Bor " Iterator&er$on> iter = *omp!getEmploee"#Biter!a$?ext"# #- &er$on p = iter!next"#B i" p!age > 0 #- per$on$!add"p#B ((

    2ava !

    */

  • 8/13/2019 OCL Slide Share

    37/118

    Colle,t o%eration

    /ollect*perationret$rns a ne" ,olle,tion fro ane0isting one+

    $ Res$lt of collectal"ays $ag*T++Tdefines t#ety%e of t#e %ro%erty to be ,olle,ted

    E0a%le

    $ self.employees 5 collect(age) Ret$rn ty%e*Bag!Integer)

    5#ort notation for ,olle,t* self.employees.age

    collection +, collect( v : Type - e*p(v) )collection +, collect( v - e*p(v) )collection +, collect( e*p )

  • 8/13/2019 OCL Slide Share

    38/118

  • 8/13/2019 OCL Slide Share

    39/118

    Iterator&based o%erations

    ,or-ll,#e,9s> if all eleents of a ,olle,tion eval$ate to tr$e+ Eample#self+e%loyees & forAll!age if at least one eleent eval$ates to tr$e

    $ 5elf+e%loyees & e0ists!e* E%loyee e+isManager H tr$e)

    collection +, forAll( v : Type - boolean&*p(v) )collection +, forAll( v - boolean&*p(v) )collection +, forAll( boolean&*p )

    *ontext Companyinv:

    $el!emploee>orAll "e1 H $el!emploee > orAll "e2 H e1 > e2 implie$ e1!id > e2!id##

    *ontext Companyinv:

    $el!emploee > orAll "e1' e2 H e1 > e2 implie$ e1!id > e2!id##

  • 8/13/2019 OCL Slide Share

    40/118

    Iterate

    %terateis t#e generi, for of all iterator&based o%erations

    Synta

    ,olle,tion & iterate! elem* 'y%W acc* 'y% HinitE0% ep(elem> acc) )

    7ariable elemis a ty%edIterator

    7ariable accis a ty%edAccumulator

    Gets assigned initial val$e initE0%

    ep(elem/ acc) is a f$n,tion to ,al,$late acc

    ,olle,tion & ,olle,t! 0 * ' 0+%ro%erty )00 semantically e&uialent to#

    ,olle,tion & iterate! 0 * 'W a,, * ' H BagPQ a,, & in,l$ding!0+%ro%erty) )

  • 8/13/2019 OCL Slide Share

    41/118

    Iterate

    E0a%le

    $ 5etP > Q & iterate!i*Integer> a*IntegerHF a?i)

    $ Res$lt*

    *olle*tion > iterate"x : B a** : 2 = val/e H a** > /"a**' x#

    iterate (coll : T, acc : T2 = value){

    acc=value;

    for( IteratorT! iter =

    coll.get"lements(); iter.#as$ext(); ){

    T elem = iter.next();

    acc = u(elem, acc);

    %

    %

    2ava !

    */

  • 8/13/2019 OCL Slide Share

    42/118

    '$%le ty%es

    '$%le ty%es are str$,t$red ,reated "it# t#e9ey"ord '$%le and by additionally s%e,ifying%art naes and %art val$es+

    '$%les and ,olle,tions are ort#ogonal

    5etP'$%lePnae*=Ada=>eails*5etP=ada-a,=>=ada-ib=QQ>'$%lePnae*=Bob=>eails*5e@$en,eP=bob-og=>=bob-s$n=QQQ *

    5et!'$%le!eails*Colle,tion!5tring)>nae*5tring))

    E0a%le * Alternative e@$ivalent .CL&

  • 8/13/2019 OCL Slide Share

    43/118

    E0a%le * Alternative> e@$ivalent .CL&for$lations

    Person

    name: ,tring

    %arent

    ,#ildren

    F++K

    "onstrain* A %erson is not its o"n ,#ild

    o many different formulations can you find?

    E0a%le * Alternative e@$ivalent

  • 8/13/2019 OCL Slide Share

    44/118

    E0a%le * Alternative> e@$ivalent.CL&for$lations !select(k k ! self""->si#e(" ! $

    '#e N$ber of ,#ildren for ea,# %erson self> "#ere t#e ,#ildren are

    t#e %erson self> #ave to be F+

    (self.children->select(k k ! self""->is%mpty("'#e set of ,#ildren for ea,# %erson self> "#ere t#e ,#ildren are t#e

    %erson self> #as to be e%ty+

    Person

    name: ,tring

    %arent

    ,#ildren

    F++K

    "onstrain* A %erson is not its o"n ,#ild

    E0a%le * Alternative e@$ivalent

  • 8/13/2019 OCL Slide Share

    45/118

    E0a%le * Alternative> e@$ivalent.CL&for$lations !)

    not self.children->includes(self"

    It is not %ossible> t#at t#e set of ,#ildren of ea,# %erson self ,ontains

    t#e %erson self+

    self.children->excludes(self"&he set of children of each person 'self cannot contain

    'self.

    Person

    name: ,tring

    %arent

    ,#ildren

    F++K

    "onstrain* A %erson is not its o"n ,#ild

    E0a%le * Alternative e@$ivalent

  • 8/13/2019 OCL Slide Share

    46/118

    E0a%le * Alternative> e@$ivalent.CL&for$lations !)

    et{self)->intersection(self.children"->is%mpty("

    '#e interse,tion bet"een t#e one eleent set> "#i,# only in,l$des one%erson self and t#e set of t#e ,#ildren of self #as to be e%ty+

    (self.children->re*ect(k k +> self""->is%mpty("

    '#e set of ,#ildren for ea,# %erson self> for "#oe does not a%%ly>t#at t#ey are not e@$al to t#e %erson self> #as to be e%ty+

    Person

    name: ,tring

    %arent

    ,#ildren

    F++K

    "onstrain* A %erson is not its o"n ,#ild

    E0a%le * Alternative e@$ivalent

  • 8/13/2019 OCL Slide Share

    47/118

    E0a%le * Alternative> e@$ivalent.CL&for$lations !)

    self.children->forAll(k k +> self"

    Ea,# ,#ild of t#e %erson self is not t#e %erson self+

    not self.children->exists(k k ! self"

    '#ere is no ,#ild for ea,# %erson self> "#i,# is t#e %erson self

    Person

    name: ,tring

    %arent

    ,#ildren

    F++K

    "onstrain* A %erson is not its o"n ,#ild

    aving so many ays to e"press each constraint is good or

    #ad?

  • 8/13/2019 OCL Slide Share

    48/118

    O"L 1etamodel (epressions)

    Attri/teGallExp

    .eat#reCall&*

    p

    ?avigationGallExp

    6perationGallExp

    A$$o*iationEndGallExp

    A$$o*iationGla$$GallExp

    Operation Attrib#te

    Association&n!AssociationClas

    s

    1 1

    1 1

    .nly in UML

    -n O"L epression as an instance

  • 8/13/2019 OCL Slide Share

    49/118

    -n O"L epression as an instanceof the O"L 11

    contet "ategory in# self2customer0+for-ll(c3 c2sale0+

    select(payment4ate+no5())2amount0+sum()*=self2maPending-mount):IteratorExp(forAll)

    :OperationCallExp

    (

  • 8/13/2019 OCL Slide Share

    50/118

    So you thin6 you 6no5 O"L7

    0

  • 8/13/2019 OCL Slide Share

    51/118

    allInstan,es

    Car**allInstan,es !) * 5et!Car)

    5tring**allInstan,es!) * 5et!5tring) 111

    Careful ith the allInstances operation. $o not apply on infinite

    types!

  • 8/13/2019 OCL Slide Share

    52/118

    ll

  • 8/13/2019 OCL Slide Share

    53/118

    Colle,tions

    C ll i

  • 8/13/2019 OCL Slide Share

    54/118

    Colle,tions

    5ets are insensible to insertion order andfre@$en,y

    .rdered 5tes are sensible to order> insensibleto fre@$en,y

    Bags are sensible to fre@$en,y> insensible toorder

    5e@$en,e are sensible to bot#

  • 8/13/2019 OCL Slide Share

    55/118

    C ll ti C ti

  • 8/13/2019 OCL Slide Share

    56/118

    Colle,tion Casting

    5oe abig$os ,onversions

    5e@$en,ePS>T>T>SQ&as5et!) H 5etPT>SQ *

    5e@$en,ePS>T>T>SQ&asBag!) H BagPT>T>S>SQ

    5etPS>T>T>SQ&as5e@$en,e!)

    1 5e@$en,ePT>SQ 15e@$en,ePS>TQ

    Implementator&s decision!!

    Also others li'e (

    Set)*%+%,-/any0true1

    C ll ti E lit

  • 8/13/2019 OCL Slide Share

    57/118

    Colle,tion E@$ality

    5etPT>SQ H 5etPS>T>TQ

    5etPT>SQ H BagPT>SQ

    .rdered5etPS>VQ H 5e@$en,ePS>VQ

    .rdered5etPT>S>SQ H .rdered5etPT>S>TQ

    .rdered5etPT>V>SQ H .rdered5etPV>T>SQ

    I i t it# d fi d

  • 8/13/2019 OCL Slide Share

    58/118

    Invariants "it# $ndefined

    Constraints are violated if t#ey do not eval$ateto tr$e

    $ Co%anies "it# a anager "it# age$ndefined "ill violate t#e ,onstraint

    $ (#at "o$ld #a%%en in 56L1

    Person

    age : intgetAge"# : int

    Companymanager emploe

    r

    0!!1 0!!1

    Conte"t Company inv(

    Self.manager.age/2+

    I i t it# d fi d !)

  • 8/13/2019 OCL Slide Share

    59/118

    Invariants "it# $ndefined !)

    (e need to ,#e,9 for $ndefinedness

    $ If not self+anager+o,lIsUndefiend t#enself+anager+age

  • 8/13/2019 OCL Slide Share

    60/118

    Re,$rsive .CL @$eries

    Conte0t 3erson inv*self&as5et!)&,los$re!,#ildren)

    Clos$res added in t#e last version of .CL

    Person

    name: ,tring

    %arent

    ,#ildren

    F++K

    "onstrain* A %erson ,annot be #is o"n an,estor

    .CL in %ost,onditions !frae %roble

  • 8/13/2019 OCL Slide Share

    61/118

    % ! %also in .CL)

    context'epartment::oal)val!ation(#

    post: self.s!m*ales=self.emplo+ee.sales.amo!nt,>s!m(# and if self.s!m*ales>self.goal ten

    self.emplo+ee,>for-ll(e e.salar+= e.salar+/pre 0 e.ategor+.raise#

    else self.arleet,>exl!des-ll(Car::allnstanes,>selet( .t+pe=45!x!r+6##

    endif

    Or $%ere $e c%an!e t%e cate!or" $%ere t%e emplo"ee belon!s to&inal states $%ere not referenced ob'ects are modified also satisf" t%e

    postcondition

    Or final states $%ere $e assi!n a ero alue to sum&alesand remoe

    all sales from t%e emplo"eesOr $%ere $e remoe t%e emplo"ees of a departmentOr final states $%ere t%e idof t%e department is modifiedOr $%en $e add*remoe non+luxur" cars to t%e department

    (or remoe all cars)

    If emplo"ees %ae sold enou!% to fulfill t%e !oal, t%eir salar" is

    increased as indicated b" t%eir cate!or"- Ot%er$ise, emplo"ees are

    not lon!er allo$ed to use luxur" cars

    Category

    Sale1..*

    name : String

    raise: Money

    id : Naturalamount: Money

    *Employee

    name : Stringsalary: Money

    *1

    Department

    id: Naturalgoal: Money

    sumSales: Money

    1..*1

    CarlicensePlate : Stringtype: String

    1*carFleet

  • 8/13/2019 OCL Slide Share

    62/118

    (1issing) O"L li!raries

    2

  • 8/13/2019 OCL Slide Share

    63/118

    5oe e0a%les !

  • 8/13/2019 OCL Slide Share

    64/118

    5oe e0a%les !

  • 8/13/2019 OCL Slide Share

    65/118

    5oe e0a%les !/)

    AL: 5et/rn$ te aritmeti* average val/e ote element$ in te nonempt *olle*tion!

    G6A5IA?GE: 5et/rn$ te *ovarian*e val/eetCeen tCo ordered $et$

    ,onte0t Colle,tion**avg!)*Real%re* selfnotE%ty!)%ost* res$lt H selfs$!) / selfsiDe!)

    ,onte0t .rdered5et**,ovarian,e!8* .rdered5et)*Real%re* selfsiDe!) H 8siDe!) and selfnotE%ty!)%ost*

    let avg8*Real H 8avg!) in let avg5elf*Real H selfavg!) in res$lt H !

  • 8/13/2019 OCL Slide Share

    66/118

    5oe e0a%les !/)

    M6E: 5et/rn$ te mo$t re/ent val/e in a*olle*tion!

    E,GE?I?L 5A?: 5et/rn$ te po$ition "i!e!'ran+ing# o an element Citin a Golle*tion!

    ,onte0t Colle,tion**ode!)* '%re* selfnotE%ty!)%ost* res$lt H selfany!e selfforAll!e self,o$nt!e) H self,o$nt!e))

    ,onte0t Colle,tion**ran92es,ending!e* ')* Integer

    %re* selfin,l$des!e)%ost* res$lt H selfsiDe!) & selfsele,t!e eHe)siDe!) ? on,et#e verifi,ation%ro,ess ends+

    Resol$tion of t#e C53

  • 8/13/2019 OCL Slide Share

    95/118

    Using EM4toC53 !and 7II)

  • 8/13/2019 OCL Slide Share

    96/118

    g ! )

    Output :1odel instance

    '#e instan,e

    %roves t#at t#eodel satisfiest#e ,orre,tness

    %ro%ertiessele,ted+

  • 8/13/2019 OCL Slide Share

    97/118

    'ranslation of .CL invariants

  • 8/13/2019 OCL Slide Share

    98/118

    : ;

    [) *&

    // Eval$ate s$be0%ressions

    self!7ars> )>

    arg!> "ordCo$ntZ> [)+

    ,onstant !8)*&

    8 H ) *&

    // is t#e only visible var

    nt# 7ars> )+

    : ;

  • 8/13/2019 OCL Slide Share

    99/118

    less'#an!> Res$lt)*&

    // Eval$ate s$be0%ressions attrib$te!> [)>

    ,onstant!> 8)>

    // Cobine %artial res$lts

    \![>8> Res$lt)+

    : ;

  • 8/13/2019 OCL Slide Share

    100/118

    All t#is "it# t#e #el% of 3rolog library for .CL!FFF L.C)

    Oey eleent of ECLi35e !t#e ,onstraint solver)& s$%%ort of a #ig#er&order %redi,ate

    ocl7int7greater7than(0nstances, 8ars, 6red1, 6red$, 9esult) :

    apply(6red1, ;0nstances, 8ars, =), ] 8 is t#e res$lt ofeval$ating 3red

    9esult::..1, ] Res$lt is a boolean val$e

    ?5(, 9esult). ] Res$lt is tr$e iff [ 8

  • 8/13/2019 OCL Slide Share

    101/118

    Code Generation for .CL e0%ressions

  • 8/13/2019 OCL Slide Share

    102/118

    .CL e0%ressions $st be %ro%agated to t#esyste i%leentation

    7ery very liited tool s$%%ort for t#is !and noteffi,ient big s,alability iss$es)

    'y%i,ally M2E tools liit validation to t#e in%$tfors and/or %rovide a sall 25L to e0%resst#e r$les t#ey ,an enfor,e

    5o> #o" "o$ld yo$ i%leent .CL,onstraints1

    '#e effi,ien,y %roble

  • 8/13/2019 OCL Slide Share

    103/118

    C' (Cs#

    *+sem state *

    (onsistent#

    C' (Cs#

    *6

    onsistentI

    -ll Cs are satisfied

    *et of modifiation events

    Goal

  • 8/13/2019 OCL Slide Share

    104/118

    o propose a metod to efficiently deide te onsisten+ of *6

    wrt C'

    )ffiien+ = 9!m"er of instanes of *tate6 tat m!st "e onsidered

    wen eDing its onsisten+

    e metod so!ld "e tenologiall+ independent 9ot "o!nd to an+ tenologial ass!mption

    e res!lts ma+ "e !sed to implement te C* in an+ platform

  • 8/13/2019 OCL Slide Share

    105/118

    A si%le e0a%le

  • 8/13/2019 OCL Slide Share

    106/118

    ontext *ale inv: self.sipment,>for-ll(s

    s.planned*ip'ateJ=self.pa+ment'ate03A#

    *ipmentKs1 2L8AN 4Porto6Ks2 2L8AN 4rondeim6Ks3 17AN 45!xem"o!rg6Ks& 1BAN 4@iga6

    KsL 128AN 4Olagenf!rt6. . .Ksn 181A76oronto6

    *aleKs11AAA 18ANKs22AAA 18ANKs3 3A 1A8ANKs& 2AA 1A8AN. . .Ksn 12AA 1L1A7

    pdate-ttri"!te(*ale pa+ment'ate Ks1 2ANN#pdate-ttri"!te(*ipment planned*ip'ate s3 1BAN#

    nsert@('eliveredn Ks&KsL#*aleKs11AAA 2ANANKs22AAA 18ANKs3 3A 1A8ANKs& 2AA 1A8AN. . .Ksn 12AA 1L1A7

    *ipmentKs1 2L8AN 4Porto6Ks2 2L8AN 4rondeim6Ks3 1BAN 45!xem"o!rg6Ks& 1BAN 4@iga6

    KsL 128AN 4Olagenf!rt6. . .Ksn 181A76oronto6

    In OCL, ICs must be satisfied by all instances of the context typeOnly affected sales must be checkedot all shipments of affected sales must be considered

    Sale

    id : Naturalamount: Money

    paymentDate: Date

    Shipment

    id: NaturalplannedShipDate: Dateaddress: Address

    1..* 1..*

    DeliveredIn

    Code Generation

  • 8/13/2019 OCL Slide Share

    107/118

    '#e generated e0%ressions ay be $sed for ,ode&generation

    et#ods to effi,iently ,#e,9 t#e ,onstraints in t#e final %latfors

    4pdateAttr0payment$ate%Sale1

    Constraint 5alidShip$ate

    s.shipment/forAll0sh6sh.plannedShip$ate78s.payment$ate9:;1

    Method!Sale s"#$

    % . . . s.paymentDate & value' #

    (()eriication o e+pression ,

    Iterator setsh & s.shipments.iterator!$'

    -hile ! setsh.hasNe+t!$ $

    % Shipment sh & !Shipment$ setsh.ne+t!$'

    I !sh.plannedShipDates.paymentDate/,0$

    thro- ne- +ception!2Invalid date3$'

    4

    4

    create trigger uPaymentDate

    5eore update o PaymentDate on Sale or each ro-

    Declare v6rror N7M89'

    InvalidDate +ception'

    8egin )eriication o e+pression ,

    S;M DeliveredIn d" Shipment sh

    ?@9 d.sale & :ne-.id and d.shipment & sh.id

    and sh.plannedShipDate:ne-.paymentDate/,0'

    I !v6rror0$ then raise InvalidDate' end i'

    nd

  • 8/13/2019 OCL Slide Share

    108/118

    Shameless pu!licity

    108

    '#e Modeling 3ortal

  • 8/13/2019 OCL Slide Share

    109/118

    Modeling&lang$ages+,o ? -softodeling

    .CL (or9s#% F

  • 8/13/2019 OCL Slide Share

    110/118

    Co&lo,ated "it# Mo2EL5 F

  • 8/13/2019 OCL Slide Share

    111/118

    To 6eep in touch# 'ordi2ca!otinria2fr

    111

    Appendix

    ?C5 *tandard 5i"rar+

  • 8/13/2019 OCL Slide Share

    112/118

    .?C5-n+ operations

    .

    *tring operations. nteger@eal operations

    . oolean operations

    . Colletion operations

    . terator,"ased Colletion operations

  • 8/13/2019 OCL Slide Share

    113/118

    Appendix

    *tring operations

  • 8/13/2019 OCL Slide Share

    114/118

    Operation .otation eturn alue typeconcatenation s/concat('trin%) *tring

    sie s/si$e() nteger

    to lo$er case s/toLoer() *tring

    to upper case s/to0pper() *tring

    substrin! s/s#bstrin%(Inte%er

    Inte%er)*tring

    e7uals s1 = s2 oolean

    not e7uals s1 , s2 oolean

    Appendix

    nteger@eal operations

  • 8/13/2019 OCL Slide Share

    115/118

    Operation .otation eturn alue type

    plus a 3 b nteger@eal

    minus a 4 b nteger@ealmultiplication a 5 b nteger@eal

    diision a 6 b @eal

    modulus a/mo!(b) nteger

    inte!er diision a/!iv(b) nteger

    maximum a/ma*(b) nteger@eal

    minimum a/min(b) nteger@eal

    round a/ro#n!() nteger

    floor a/floor() nteger

    absolute alue a/abs() nteger@eal

    e7uals a = b oolean

    not e7uals a , b oolean

    less a b oolean

    more a , b oolean

    less or e7ual a = b oolean

    more or e7ual a ,= b oolean

  • 8/13/2019 OCL Slide Share

    116/118

    Appendix

    Colletion operations

  • 8/13/2019 OCL Slide Share

    117/118

    Operation eturn alue type

    count(object) nteger

    ecludes(object) oolean

    ecludesAll(collection)

    oolean

    includes(object) ooleanincludesAll(collection)

    oolean

    is!"pty() oolean

    not!"tpy() oolean

    si#e() nteger

    su"() nteger@eal

  • 8/13/2019 OCL Slide Share

    118/118