24.6.2008 formal methods of systems specification logical specification of hard- and software dr....

12
24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur und Softwaretechnik Prof. Dr. Holger Schlingloff

Upload: maya-bauer

Post on 26-Mar-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008

Formal Methods of Systems SpecificationLogical Specification of Hard- and Software

Dr. Armin WolfFraunhofer Institut für Rechnerarchitektur und

Softwaretechnik

Prof. Dr. Holger Schlingloff

Page 2: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 2H. Schlingloff, Logical Specification

OCL

• Object constraint language• (important) Part of UML• Specifies constraints on model elements

„A constraint is a restriction on one or more values of (part of) an object-oriented model or system“

• Different kinds of constraints invariant - a constraint that must always be met by all

instances of a class precondition of an operation - a constraint that must always

be true before the execution of the operation postcondition of an operation - a constraint that must always

be true after the execution of the operation guard of a transition – a constraint that must be met before a

state transition fires

Page 3: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 3H. Schlingloff, Logical Specification

Semantics of UML 2

• 13 diagram types• Common meta-model• Instances (objects) can occur in several

diagrams, different views onto the same thing• A structure diagram, e.g. a class, defines a

collection of objects with similar properties, attributes and methods signature and structure

• A behavioural diagram, e.g. a statechart, defines a collection of behaviours of objects change of model in time

Page 4: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 4H. Schlingloff, Logical Specification

Connection UML-OCL

• Each OCL formula can mention objects defined in UML diagrams

• OCL semantics „relative“ to a certain UML model

• Expressions in OCL „add information“ to UML diagrams not a „stand-alone“ specification language OCL for constraints which cannot be expressed by

diagrams- e.g. number of passengers in a flight is less or equal to the

number of seats in the plane

- fixed interpretation (includes arithmetics)

Page 5: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 5H. Schlingloff, Logical Specification

Standardisation

• early 1990s: Steve Cook and John Daniels, Syntropy design method adaptation of Z to OOA

• 1996: OMG request for proposal; IBM and ObjectTime Ltd. submit joint proposal

• 1997: OCL 1.1

• 1.5.2006: OCL 2.0

Page 6: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 6H. Schlingloff, Logical Specification

A Simple Example (from Wikipedia)

Informelle Beschreibung1. Das Alter einer Person ist nicht negativ. 2. Eine Person ist jünger als ihre Eltern.

3. Nach einem Geburtstag ist eine Person

um genau 1 Jahr älter. 4. Eine Person hat genau 2 Eltern. 5. Wenn jemand ein Kind bekommen hat,

ist die Menge seiner Kinder nicht leer und die Anzahl seiner Kinder ist größer als vorher.

6. Nur eine erwachsene Person darf ein Auto besitzen.

7. Die Erstzulassung eines Autos liegt nicht vor dem Baujahr.

OCL-Constraint• Context Person inv: self.alter >=0 • Context Person inv: self.Eltern->forall(e|

e.Alter>self.Alter) • Context Person::hatGeburtstag() post:

self.Alter=self.Alter@pre+1 • Context Person inv: self.Eltern->size()=2 • Context Person::bekommtKind() post:

self.Kinder->notEmpty() and self.Kinder->size() > self.Kinder@PRE->size()

• Context Person inv: Alter<18 implies autos->size()=0

• Context Auto inv: Erstzulassung>=Baujahr

Page 7: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 7H. Schlingloff, Logical Specification

OCL Types

• Basic type „void“: void::oclIsUndefined

• Boolean, Integer, Real, String, …• Enumerations: enum{val1, val2, val3}

• Set, Bag, Sequence union(Bag{2,2,3}, Bag{3,3})

• Class types: each class name can be used as a type most general class/type: OclAny

• Strong typing rules, subtyping according to OO Integer is subtype of Real Each type conforms to each of ist supertypes

Page 8: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 8H. Schlingloff, Logical Specification

OCL Contexts

• The context attaches a constraint to a particular modelling element context <class name> :: <operation> (<parameters>) pre: <Boolean OCL expression>

• Dot-notation allows access to other (visible) modelling elements or objects Meeting.start, Passagier.name

• „self“ always refers to the object identifier from which the constraint is evaluated context Meeting inv: self.end > self.start

• Access to collections via -> Passagier.buchung->size()

Page 9: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 9H. Schlingloff, Logical Specification

OCL Operators

• Boolean operators: =, and, or, xor, not, implies, if-then-else, forall sequential evaluation,

i.e. (true or undefined) = true x implies y = (not x) or (x and y)

• @pre-operator refers to the previous value of an object in a

postcondition

• select-operator collection->select(condition) is any element of the

collection satisfying the condition e.g. Passagier.buchung->select(datum=TODAY)

Page 10: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 10H. Schlingloff, Logical Specification

Pre- and Postconditions

•Used to constrain methods• context Meeting :: confirm() pre: Calendar.freeTimeSlot (self.start, self.duration())post: self.isConfirmed = true

• context Meeting :: duration(): Integer post: result = self.end – self.start

• context Meeting :: shift(d: Integer) post: start = start@pre + d and end = end@pre + d

Page 11: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 11H. Schlingloff, Logical Specification

Iterations

c->iterate(x:T1; a:T2 = exp0 | exp ) c is of type Collection(T) x is a name for a variable (sometimes called the

”cursor”) x is of a type T1 which is conformant to T a is the name for a variable (sometimes called the

”accumulator”) a is of type T2 exp0 is an OCL expression giving a value of type T2 exp is an OCL expression using the variables x and a

and giving a value of type T2 The type of the whole ”iterate” expression is of type T2

Page 12: 24.6.2008 Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur

24.6.2008 Slide 12H. Schlingloff, Logical Specification

Predefined iterations

• c:Collection(T)->size: Integerpost: result = c->iterate(e:OclAny;

a:Integer = 0 | a+1)• c:Collection(T)->isEmpty: Booleanpost: result = c->size = 0

• c:Collection(T)->forAll(expr: OclExpression): Booleanpost: result = c->iterate(e:OclAny;

a: Boolean = true | a and expr)• c:Collection(T)->exists(expr: OclExpression): Booleanpost: result = c->iterate(e:OclAny;

a: Boolean = false | a or expr)