Académique Documents
Professionnel Documents
Culture Documents
In theory, there is no difference between theory and practice. But, in practice, there is.
Jan L. A. van de Snepscheut/Yogi Bera
Foundation: Assertions
An assertion is a predicate (i.e., a truefalse statement) placed in a program to indicate that the developer thinks th t the that th predicate di t is i always l true t at t that th t place l [Wikipedia]. [Wiki di ] Usage g in Hoare logic [Hoare 1969] Design by contract [Meyer 1986, Eiffel] For run-time run time checking (Java (assert t), ) JML JML, JASS, JASS SQL, SQL ) During the development cycle (debugging) Static assertions at compile time
Object Constraint
Model-based assertion [Warmer [ and d Kleppe] l ]d define f a constraint as f follows: ll A A constraint is a restriction on one or more values of (part of) an object-oriented model or system. OCL as specification language for object constraints
History of OCL
Developed at IBM in 1995 originally as a business engineering language Adopted as a formal specification language within UML Part of the official OMG standard for UML (from version 1.1 on) Used for precisely defining the well-formedness rules (WFRs) for UML and further OMG-related metamodels Current version is OCL 2.0 20
Literature
[1] Warmer, [ , J., , Kleppe, pp , A.: The Object j Constraint Language. g g
Precise Modeling with UML. Addison-Wesley, 1999 [2] Warmer, J., Kleppe, A.: The Object Constraint Language Second Edition. Getting Your Models Ready For MDA. Addison-Wesley, 2003 [3] OMG UML specification, www.omg.org/technology/documents/modeling spec catalo www.omg.org/technology/documents/modeling_spec_catalo g.htm#UML [4] OMG UML 2.0 OCL, www omg org/technology/documents/formal/ocl htm www.omg.org/technology/documents/formal/ocl.htm [5] Heinrich Humann: Formal Specification of Software Systems. Course, 2000, Technische Universitt Dresden
Dr. Birgit Demuth MINE Summer School, Nida, 2009 8
Constraint
Definition A constraint is a restriction on one or more values of (part of) an object-oriented model or system system. A constraint is formulated on the level of classes, but its semantics is applied on the level of objects. originally formulated in the syntactic context of a UML UML model (i.e. (i e a set of UML diagrams)
10
Invariant
Definition An invariant is a constraint that should be true for an object during its complete lifetime. Invariants often represent rules that should hold for the real-life objects after which the software objects are modeled. Syntax context <classifier> inv [<constraint name>]: <Boolean OCL expression> p
Dr. Birgit Demuth MINE Summer School, Nida, 2009 11
OCL/UML By Example
12
Invariant - Examples
context Meeting g inv: self.end > self.start
Equivalent Formulations
13
14
Precondition
Definition Constraint that must be true just prior to the execution of an operation Syntax context <classifier>::<operation> (<parameters>) pre [<constraint name>]: <Boolean OCL expression> p
15
Precondition - Examples
context Meeting::shift(d:Integer) pre: self.isConfirmed = false context Meeting::shift(d:Integer) pre: d>0 context Meeting::shift(d:Integer) pre: self.isConfirmed = false and d>0
16
Postcondition
Definition Constraint C t i t that th t must t be b t true just j t after ft to t the th execution ti of an operation Postconditions are the way how the actual effect of an operation is described in OCL. Syntax context <classifier>::<operation> (<parameters>) post [<constraint name>]: <Boolean OCL expression>
Dr. Birgit Demuth MINE Summer School, Nida, 2009 17
Postcondition - Examples
context Meeting::duration():Integer post: result = self.end self.start -- keyword result refers to the result of the operation context Meeting::confirm() post: self.isConfirmed = true
18
19
20
23
25
Navigation Expressions
Association ends (role names) are be used to navigate navigate from one object in the model to another object. Navigations are treated as attributes (dot-Notation). The type of a navigation expression is either a User defined type (association end with multiplicity at most 1) Collection (association end with multiplicity > 1)
Dr. Birgit Demuth MINE Summer School, Nida, 2009 26
User defined type Navigation from Meeting to moderator results in type Teammember context Meeting inv: self.moderator.gender = Gender::female
27
Collection Navigation von Meeting to participants results in type Set(Teammember) context Meeting inv: self->collect(participants)->size()>=2 or with shorthand notation: context Meeting inv: self.participants->size()>=2
Dr. Birgit Demuth MINE Summer School, Nida, 2009 28
30
32
33
Flattening of Collections
Automatic flattening rule for all nested collections self.participants.meetings in the context Meeting What happens? self.participants delivers a Set(Person) self.participants.meetings p p g delivers a Bag(Set(Person) Results in a Bag(Person)
Dr. Birgit Demuth MINE Summer School, Nida, 2009 34
35
context Meeting::isConfirmed g : Boolean init: false context Teammember:meetings : Set(Meetings) init: Set{}
Note that an initial value must be valid only at the object creation time!
36
37
38
context Meeting def: noConflict : Boolean = participants.meetings->forAll(m|m<>self and m.isConfirmed implies not self.inConflict(m))
Dr. Birgit Demuth MINE Summer School, Nida, 2009 39
Limitations of OCL
No support for inconsistency detection for OCL Frame Problem Operations are specified by what they change (in postconditions), d ) with h the h implicit l assumption that h everything h else (the frame) remains unchanged Limited recursion allInstances() Problem: Person.allInstances() allowed not allowed for infinite types such as Integer.allInstances()
Dr. Birgit Demuth MINE Summer School, Nida, 2009 41
Statechart diagram Interaction diagram Activity diagram Component p diagram g Use case diagram
42
Whenever a subexpression of an OCL expression evaluates to undefined, then the whole term evaluates to undefined Exceptions
T True or undefined d fi d = True T False and undefined = False False implies p undefined = True
Dr. Birgit Demuth MINE Summer School, Nida, 2009 44
45
46
Model Layer
Examples
M2 Specification of WFRs in OMG standards (Metamodel) Definition of Modeling Guidelines for DSLs Specification of Model Transformations M1 (Model) Model Verification ( CASE-Tool) Evaluation Evaluation of modeling guidelines Execution of model transformations Specification of Business Rules/Constraints Specification of Test Cases M0 (Objects) ( j )
Dr. Birgit Demuth
49
50
51
52
53
54
55
56
57
58
Acronyms
OCL OMG MOF PRR QVT UML WFR Object Constraint Language Object Management Group M t Obj t F Meta-Object Facility ilit Production Rule Representation Query Views Transformation Unified Modeling Language Well-Formedness Rule
59
60