Software Design, Modelling and Analysis in UML Lecture 5: Object Diagrams 2015-11-05 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal – 5 – 2015-11-05 – main – Albert-Ludwigs-Universit¨ at Freiburg, Germany Contents & Goals Last Lecture: • OCL Semantics This Lecture: • Educational Objectives: Capabilities for following tasks/questions. • What does it mean that an OCL expression is satisfiable? • When is a set of OCL constraints said to be consistent? • What is an object diagram? What are object diagrams good for? • When is an object diagram called partial? What are partial ones good for? • When is an object diagram an object diagram (wrt. what)? • How are system states and object diagrams related? • Can you think of an object diagram which violates this OCL constraint? – 5 – 2015-11-05 – Sprelim – • Content: • OCL: consistency, satisfiability • Object Diagrams • Example: Object Diagrams for Documentation 2 /33
OCL Satisfaction Relation – 5 – 2015-11-05 – main – 3 /33 OCL Satisfaction Relation In the following, S denotes a signature and D a structure of S . Definition (Satisfaction Relation). Let ϕ be an OCL constraint over S and σ ∈ Σ D S a system state. We write • σ | = ϕ if and only if I � ϕ � ( σ, ∅ ) = true . • σ �| = ϕ if and only if I � ϕ � ( σ, ∅ ) = false . – 5 – 2015-11-05 – Soclsat – Note : In general we can’t conclude from ¬ ( σ | = ϕ ) to σ �| = ϕ or vice versa. 4 /33
OCL Consistency Definition (Consistency). A set Inv = { ϕ 1 , . . . , ϕ n } of OCL constraints over S is called consistent (or satisfiable) if and only if there exists a system state of S wrt. D which satisfies all of them, i.e. if ∃ σ ∈ Σ D S : σ | = ϕ 1 ∧ ... ∧ σ | = ϕ n and inconsistent (or unsatisfiable) otherwise. – 5 – 2015-11-05 – Soclsat – 5 /33 Example: OCL Consistent? location TeamMember Meeting Location 2..* meetings * name : String title : String name : String participants * meeting 1 age : Integer numParticipants : Integer start : Date duration: Time move(newStart : Date) ((C) Prof. Dr. P. Thiemann, http://proglang.informatik.uni-freiburg.de/teaching/swt/2008/ ) • context Location inv : name = ’Lobby’ implies meeting -> isEmpty () • context Meeting inv : title = ’Reception’ implies location . name = ’Lobby’ – 5 – 2015-11-05 – Soclsat – • allInstances Meeting -> exists ( w : Meeting | w . title = ’Reception’ ) 6 /33
Deciding OCL Consistency • Whether a set of OCL constraints is consistent or not is in general not as obvious as in the made-up example. • Wanted : A procedure which decides the OCL satisfiability problem. • Unfortunately : in general undecidable . OCL is as expressive as first-order logic over integers. – 5 – 2015-11-05 – Soclsat – 7 /33 Deciding OCL Consistency • Whether a set of OCL constraints is consistent or not is in general not as obvious as in the made-up example. • Wanted : A procedure which decides the OCL satisfiability problem. • Unfortunately : in general undecidable . OCL is as expressive as first-order logic over integers. – 5 – 2015-11-05 – Soclsat – • And now ? Options: Cabot and Claris´ o (2008) • Constrain OCL, use a less rich fragment of OCL. • Revert to finite domains — basic types vs. number of objects. 7 /33
OCL Critique – 5 – 2015-11-05 – main – 8 /33 OCL Critique • Concrete Syntax / Features “The syntax of OCL has been criticized – e.g., by the authors of Catalysis [...] – for being hard to read and write. • OCL’s expressions are stacked in the style of Smalltalk, which makes it hard to see the scope of quantified variables. • Navigations are applied to atoms and not sets of atoms, although there is a collect operation that maps a function over a set. • Attributes, [...], are partial functions in OCL, and result in expressions with undefined value.” Jackson (2002) – 5 – 2015-11-05 – Soclcritique – 9 /33
OCL Critique • Expressive Power : “Pure OCL expressions only compute primitive recursive functions, but not recursive functions in general.” Cengarle and Knapp (2001) • Evolution over Time : “finally self .x > 0 ” Proposals for fixes e.g. Flake and M¨ uller (2003). (Or: sequence diagrams.) • Real-Time : “Objects respond within 10s” Proposals for fixes e.g. Cengarle and Knapp (2002) • Reachability : “After insert operation, node shall be reachable.” Fix: add transitive closure. – 5 – 2015-11-05 – Soclcritique – 10 /33 What Is OCL Good For? – 5 – 2015-11-05 – main – 11 /33
What’s It Good For? • Most prominent : Formalise requirements supposed to be satisfied by all system states. Example : “the choice panels of a VM should be consistent” context VM inv : { true , false } -> exists ( b | cp -> forAll ( c | c. wen = b )) • Not unknown : Formalise pre/post-conditions of methods ( Behavioural Features ). Then evaluated over two system states (before/after executing the method). Example : “the dispense water method should decrement win ” context DD :: dispense W pre : win > 0 post : win = win @ pre − 1 • Common with State Machines : Guards in transitions. – 5 – 2015-11-05 – Swhatis – DispenseW [ win > 0] / dispense W • Lesser known : Specify operation bodies . • Metamodeling : the UML standard is a MOF-model of UML. OCL expressions define well-formedness of UML models (cf. Lecture ∼ 21). 12 /33 Where Are We? – 5 – 2015-11-05 – main – 13 /33
You Are Here. N UML W E CD , SM ϕ ∈ OCL CD , SD S ✔ Model S = ( T , C , V, atr ) , SM expr S , SD ✔ ✔ M = (Σ D S , A S , → SM ) B = ( Q SD , q 0 , A S , → SD , F SD ) ✔ ( cons 0 , Snd 0 ) π = ( σ 0 , ε 0 ) − − − − − − − − → ( σ 1 , ε 1 ) · · · w π = (( σ i , cons i , Snd i )) i ∈ N Instances u 0 ! Mathematics G = ( N, E, f ) – 5 – 2015-11-05 – Spostmap – ! OD UML 14 /33 Object Diagrams – 5 – 2015-11-05 – main – 15 /33
Recall: Graph Definition. A node-labelled graph is a triple G = ( N, E, f ) consisting of • vertexes N , • edges E , • node labeling f : N → X , where X is some label domain, – 5 – 2015-11-05 – Sod – 16 /33 Object Diagrams Definition. Let D be a structure of signature S = ( T , C , V, atr ) and σ ∈ Σ D S a system state. Then any node-labelled graph G = ( N, E, f ) where • nodes are identities (not necessarily alive), i.e. N ⊂ D ( C ) finite , • edges correspond to “links” of objects, i.e. E ⊆ N × { v : T ∈ V | T ∈ { C 0 , 1 , C ∗ | C ∈ C }} × N, � �� � =: V 0 , 1; ∗ ∀ ( u 1 , r, u 2 ) ∈ E : u 1 ∈ dom( σ ) ∧ u 2 ∈ σ ( u 1 )( r ) , • objects are labelled with attribute valuations, and non-alive identities with “X”, i.e. X = { X } ˙ ∪ ( V � ( D ( T ) ∪ D ( C ∗ ))) – 5 – 2015-11-05 – Sod – ∀ u ∈ N ∩ dom( σ ) : f ( u ) ⊆ σ ( u ) ∀ u ∈ N \ dom( σ ) : f ( u ) = { X } is called object diagram of σ . 17 /33
Object Diagram: Examples • N ⊂ D ( C ) finite • E ⊂ N × V 0 , 1; ∗ × N • ∀ ( u 1 , r, u 2 ) ∈ E : u 1 ∈ dom( σ ) ∧ u 2 ∈ σ ( u 1 )( r ) , • f : N → X • X = { X } ˙ ∪ ( V � ( D ( T ) ∪ D ( C ∗ ))) • f ( u ) ⊆ σ ( u ) / f ( u ) = { X } if u / ∈ dom( σ ) S = ( { Int } , { C } , { x : Int , y : Int , r : C ∗ } , { C �→ { x, y, r }} ) , D ( Int ) = Z σ = { 1 C �→ { x �→ 1 , y �→ 2 , r �→ { 1 C , 3 C }}} • G = ( N, E, f ) with • nodes N = { 1 C , 3 C } • edges E = { (1 C , r, 1 C ) , (1 C , r, 3 C ) } , • node labelling f = { 1 C �→ { x �→ 1 , y �→ 2 } , 3 C �→ X } is an object diagram of σ . – 5 – 2015-11-05 – Sod – • Yes, and...? G can equivalently (!) be represented graphically as follows: 1 C : C r 3 C : C r x = 1 X y = 2 18 /33 Object Diagram: More Examples? • N ⊂ D ( C ) finite • E ⊂ N × V 0 , 1; ∗ × N • ∀ ( u 1 , r, u 2 ) ∈ E : u 1 ∈ dom( σ ) ∧ u 2 ∈ σ ( u 1 )( r ) , • f : N → X • X = { X } ˙ ∪ ( V � ( D ( T ) ∪ D ( C ∗ ))) • f ( u ) ⊆ σ ( u ) / f ( u ) = { X } if u / ∈ dom( σ ) S = ( { Int } , { C } , { x : Int , y : Int , r : C ∗ } , { C �→ { v 1 , v 2 , r }} ) , D ( Int ) = Z σ = { 1 C �→ { x �→ 1 , y �→ 2 , r �→ { 2 C }} , 2 C �→ { x �→ 13 , y �→ 27 , r �→ ∅}} , 1 C : C 2 C : C 1 C : C r r 2 C : C • • x = 1 x = 13 x = 1 x = 13 y = 2 y = 27 y = 2 1 C : C 2 C : C 1 C : C r r • • 2 C : C z = 1 x = 13 x = 1 y = 2 y = 27 y = 2 1 C : C 2 C : C 1 C : C x • • 2 C : C – 5 – 2015-11-05 – Sod – x = 1 x = 13 x = 1 y = 2 y = 27 y = 2 • 1 C : C 1 C : C 2 C : C x = 1 • x = 13 y = 2 • y = 27 r = { 2 C } 19 /33
Recommend
More recommend