• Keine Ergebnisse gefunden

Lecture 03: Object Constraint Language

N/A
N/A
Protected

Academic year: 2022

Aktie "Lecture 03: Object Constraint Language"

Copied!
23
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

main

Software Design, Modelling and Analysis in UML

Lecture 03: Object Constraint Language

2014-10-29

Prof. Dr. Andreas Podelski, Dr. Bernd Westphal

Albert-Ludwigs-Universit¨at Freiburg, Germany

(2)

Contents & Goals

032014-10-29Sprelim

Last Lecture:

• Basic Object System Signature S and Structure D, System State σ ∈ ΣDS

This Lecture:

• Educational Objectives: Capabilities for these tasks/questions:

• Please explain this OCL constraint.

• Please formalise this constraint in OCL.

• Does this OCL constraint hold in this system state?

• Give a system state satisfying this constraint?

• Please un-abbreviate all abbreviations in this OCL expression.

• In what sense is OCL a three-valued logic? For what purpose?

• How are D(C) and TC related?

• Content:

• OCL Syntax

• OCL Semantics (over system states)

(3)

Recall. . .

main

(4)

032014-10-29Srunningexa

A Complete Example: Vending Machine

22015-10-22Ssemdom

15/34

context DD inv : wen implies win > 0

(5)

(Core) OCL Syntax OMG (2006)

main

(6)

OCL Syntax 1/4: Expressions

032014-10-29Soclsyn

expr ::=

w : τ ( w )

| expr

1

=

τ

expr

2

: τ × τ → Bool

| oclIsUndefined

τ

(expr

1

) : τ → Bool

| {expr

1

, . . . ,expr

n

} : τ × · · · × τ → Set ( τ )

| isEmpty( expr

1

) : Set ( τ ) → Bool

| size( expr

1

) : Set ( τ ) → Int

| allInstances

C

: Set ( τ

C

)

| v (expr

1

) : τ

C

→ τ ( v )

| r

1

(expr

1

) : τ

C

→ τ

D

| r

2

( expr

1

) : τ

C

→ Set ( τ

D

)

Where, given S = (T,C, V,atr),

• W ⊇ {self C : τC | C ∈ C}

is a set of typed logical variables, w has type τ(w)

• τ is any type from T ∪ TB ∪ TC

∪ {Set(τ0) | τ0 ∈ T ∪ TB ∪ TC}

• TB is a set of (OCL) basic types, in the following we use TB = {Bool,Int,String}

• TC = {τC | C ∈ C} is the set of object types,

• Set(τ0) denotes the set-of-τ0 type for τ0 ∈ TB ∪ TC

(sufficient because of

“flattening” (cf. standard))

• v : T(v) ∈ atr(C), T(v) ∈ T ,

• r1 : D0,1 ∈ atr(C),

• r2 : D ∈ atr(C),

• C, D ∈ C.

(7)

Expression Examples

Soclsyn

expr ::=

w : τ(w)

| expr1=τexpr2 : τ × τ → Bool

| oclIsUndefinedτ(expr1) : τ → Bool

| {expr1,. . . ,exprn} : τ × · · · × τ → Set(τ)

| isEmpty(expr1) : Set(τ) → Bool

| size(expr1) : Set(τ) → Int

| allInstancesC : Set(τC)

| v(expr1) : τC → τ(v)

| r1(expr1) : τC → τD

| r2(expr1) : τC → Set(τD)

S0 = ({Int},{C, D},{x : Int, p : C0,1, n : C},{C 7→ {p, n}, D 7→ {x}})

(8)

Expression Examples

032014-10-29Soclsyn

expr ::=

w : τ(w)

| expr1=τexpr2 : τ × τ → Bool

| oclIsUndefinedτ(expr1) : τ → Bool

| {expr1,. . . ,exprn} : τ × · · · × τ → Set(τ)

| isEmpty(expr1) : Set(τ) → Bool

| size(expr1) : Set(τ) → Int

| allInstancesC : Set(τC)

| v(expr1) : τC → τ(v)

| r1(expr1) : τC → τD

| r2(expr1) : τC → Set(τD)

S0 = ({Int},{C, D},{x : Int, p : C0,1, n : C},{C 7→ {p, n}, D 7→ {x}})

context DD inv : wen implies win > 0

(9)

Notational Conventions for Expressions

Soclsyn

• Each expression

ω (expr

1

, expr

2

, . . . , expr

n

) : τ

1

× · · · × τ

n

→ τ

may alternatively be written (“abbreviated as”)

• expr

1

. ω (expr

2

, . . . , expr

n

) if τ

1

is an object type, i.e. if τ

1

∈ T

C

.

• expr

1

-> ω (expr

2

, . . . , expr

n

) if τ

1

is a collection type

(here: only sets), i.e. if τ

1

= Set ( τ

0

) for some τ

0

∈ T

B

∪ T

C

.

(10)

Notational Conventions for Expressions

032014-10-29Soclsyn

• Each expression

ω (expr

1

, expr

2

, . . . , expr

n

) : τ

1

× · · · × τ

n

→ τ

may alternatively be written (“abbreviated as”)

• expr

1

. ω (expr

2

, . . . , expr

n

) if τ

1

is an object type, i.e. if τ

1

∈ T

C

.

• expr

1

-> ω (expr

2

, . . . , expr

n

) if τ

1

is a collection type

(here: only sets), i.e. if τ

1

= Set ( τ

0

) for some τ

0

∈ T

B

∪ T

C

.

• Examples:

(self : τC ∈ W; v, w : Int ∈ V ; r1 : D0,1, r2 : D ∈ V )

• self . v

• self . r

1

. w

• self . r

2

-> isEmpty

(11)

OCL Syntax 2/4: Constants & Arithmetics

Soclsyn

For example : expr ::= . . .

| true , false : Bool

| expr

1

{and , or , implies} expr

2

: Bool × Bool → Bool

| not expr

1

: Bool → Bool

| 0 , −1 , 1 , −2 , 2 , . . . : Int

| OclUndefined

τ

: τ

| expr

1

{+ , − , . . . } expr

2

: Int × Int → Int

| expr

1

{ <, ≤ , . . . } expr

2

: Int × Int → Bool

Generalised notation:

expr ::= ω (expr

1

, . . . , expr

n

) : τ

1

× · · · × τ

n

→ τ

(12)

Constants & Arithmetics Examples

032014-10-29Soclsyn

expr ::= . . .

| true,false : Bool

| expr1 {and,or,implies} expr2 : Bool × Bool → Bool

| not expr1 : Bool → Bool

| 0,−1,1,−2,2, . . . : Int

| OclUndefinedτ : τ

| expr1 {+,−, . . .} expr2 : Int × Int → Int

| expr1 {<,≤, . . .} expr2 : Int × Int → Bool

S0 = ({Int},{C, D},{x : Int, p : C0,1, n : C},{C 7→ {p, n}, D 7→ {x}})

context DD inv : wen implies win > 0

(13)

OCL Syntax 3/4: Iterate

Soclsyn

expr ::= · · · | expr

1

-> iterate( w

1

: τ

1

; w

2

: τ

2

= expr

2

| expr

3

)

or, with a little renaming,

expr ::= · · · | expr

1

-> iterate(iter : τ

1

; result : τ

2

= expr

2

| expr

3

)

where

expr1 is of a collection type (here: a set Set(τ0) for some τ0),

iter W is called iterator, gets type τ1

(if τ1 is omitted, τ0 is assumed as type of iter)

result W is called result variable, gets type τ2,

expr2 in an expression of type τ2 giving the initial value for result,

(14)

Iterate: Intuitive Semantics (Formally: later)

032014-10-29Soclsyn

expr ::= expr1->iterate(iter : τ1;

result : τ2 = expr2 | expr3)

Set(τ0) hlp = expr1; τ1 iter;

τ2 result = expr2;

while (!hlp.empty()) do iter = hlp.pop();

result = expr3; od

Note: In our (simplified) setting, we always have expr1 : Set(τ1) and τ0 = τ1. In the type hierarchy of full OCL with inheritance and oclAny,

they may be different and still type consistent.

(15)

Abbreviations on Top of Iterate

Soclsyn

expr ::= expr1->iterate(w1 : τ1; w2 : τ2 = expr2 | expr3)

expr1->forAll(w1 : τ1 | expr3)

(16)

Abbreviations on Top of Iterate

032014-10-29Soclsyn

expr ::= expr1->iterate(w1 : τ1; w2 : τ2 = expr2 | expr3)

expr1->forAll(w1 : τ1 | expr3)

is an abbreviation for

expr1->iterate(w1: τ1; w2 : Bool = true | w2 and expr3).

expr1->Exists(w : τ1 | expr3)

is an abbreviation for

To ensure confusion, we may again omit all kinds of things, cf. OMG (2006).

(17)

OCL Syntax 4/4: Context

Soclsyn

context ::= context w1 : τ1, . . ., wn : τn inv : expr where wi ∈ W and τi ∈ TC for all 1 ≤ i ≤ n, n ≥ 0.

context w1 : C1, . . . , wn : Cn inv : expr

is an abbreviation for

allInstancesC1 -> forAll(w1 : τC1 | . . .

allInstancesCn -> forAll(wn : τCn | expr

) . . .

(18)

Context: More Notational Conventions

032014-10-29Soclsyn

• For

context self : τ

C

inv : expr we may alternatively write (“abbreviate as”)

context τ

C

inv : expr

• Within the latter abbreviation, we may omit the “self ” in expr , i.e. for self .v and self .r

we may alternatively write (“abbreviate as”)

v and r

(19)

Example

Soclsyn

context DD inv : wen implies win > 0

(20)

Example

032014-10-29Soclsyn

S = ({Bool, Nat},{VM,CP,DD},

{cp : CP,dd : DD0,1,wen : Bool,win : Nat},

{VM 7→ {cp,dd},CP 7→ {wen},DD 7→ {win, wen})

(21)

“Not Interesting”

Soclsyn

Among others:

• Enumeration types

• Type hierarchy

• Complete list of arithmetical operators

• The two other collection types Bag and Sequence

• Casting

• Runtime type information

• Pre/post conditions

(maybe later, when we officially know what an operation is)

• ...

(22)

References

032014-10-29main

(23)

References

main

OMG (2006). Object Constraint Language, version 2.0. Technical Report formal/06-05-01.

OMG (2011a). Unified modeling language: Infrastructure, version 2.4.1. Technical Report formal/2011-08-05.

OMG (2011b). Unified modeling language: Superstructure, version 2.4.1. Technical Report formal/2011-08-06.

Warmer, J. and Kleppe, A. (1999). The Object Constraint Language. Addison-Wesley.

Referenzen

ÄHNLICHE DOKUMENTE

Keywords: Simulation, modeling, biological neural networks, neuronal modeling, neuroscience, NEST, NESTML, MontiCore, domain specific language, code generation, C++..

This work therefore describes an approach to integrate fuzzy sets and constraints expressed in the Object Constraint Language (OCL) in a combined constraint reasoning process..

Die neue Version zwei der Unified Modeling Language (UML) ist nach der Publikation einer Reihe von intermediären „Punktversionen“ die erste tiefgreifende Neufassung der

Here three domains are related: one describes the main concepts of dependability, another one the target mathematical analysis tool, while the third one is the

Beauftragung eines Unternehmens mit der Errichtung und dem Betrieb einer Breitbandinfrastruktur der nächsten Generation („Next Generation Ac1cess“ – „NGA“) in den

Gelangt das Angebot eines nicht präqualifizierten Bieters in die engere Wahl, sind die im Formblatt 124 angegebenen Bescheinigungen innerhalb von 6 Kalendertagen nach

2 VgV: Angaben zur Qualifikation und Erfahrung des Projektleiters anhand von Nachweisen und Referenzen für Neubau Hallenbad und Sporthalle, öffentlicher Auftraggeber oder

VI.1) Angaben zur Wiederkehr des Auftrags Dies ist ein wiederkehrender Auftrag: nein VI.2) Angaben zu elektronischen Arbeitsabläufen VI.3) Zusätzliche Angaben:. 1.