lecture 12 proto ocl modularisation design patterns
play

Lecture 12: Proto-OCL, Modularisation & Design Patterns - PowerPoint PPT Presentation

Softwaretechnik / Software-Engineering Lecture 12: Proto-OCL, Modularisation & Design Patterns 2017-07-03 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universitt Freiburg, Germany 12 2017-07-03 main Topic


  1. Softwaretechnik / Software-Engineering Lecture 12: Proto-OCL, Modularisation & Design Patterns 2017-07-03 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universität Freiburg, Germany – 12 – 2017-07-03 – main –

  2. Topic Area Architecture & Design: Content • Introduction and Vocabulary VL 10 • Software Modelling I . . (i) views and viewpoints, the 4+1 view . (ii) model-driven/-based software engineering (iii) Modelling structure VL 11 . a) (simplified) class diagrams . . b) (simplified) object diagrams VL 12 c) (simplified) object constraint logic (OCL) d) Unified Modelling Language (UML) • Principles of Design . (i) modularity, separation of concerns . . (ii) information hiding and data encapsulation (iii) abstract data types, object orientation (iv) Design Patterns VL 13 • Software Modelling II – 12 – 2017-07-03 – Sblockcontent – . (i) Modelling behaviour . . a) communicating finite automata b) Uppaal query language VL 14 c) basic state-machines . . . d) an outlook on hierarchical state-machines 2 /66

  3. Content • Proto-OCL • syntax, semantics, • Proto-OCL vs. OCL. • Proto-OCL vs. Software • An outlook on UML • Principles of (Good) Design • modularity, separation of concerns • information hiding and data encapsulation • abstract data types, object orientation • ...by example • Architecture Patterns • Layered Architectures, Pipe-Filter, Model-View-Controller. • Design Patterns – 12 – 2017-07-03 – Scontent – • Strategy, Examples • Libraries and Frameworks 3 /66

  4. Partial vs. Complete Object Diagrams • By now we discussed “ object diagram represents system state ”: { 1 C 7 � { p 7 � � , n 7 � { 5 C }} , 5 C : C p n 1 C : C 1 D : D 5 C 7 � { p 7 � � , n 7 � � } , � p = � p = � x = 23 1 D 7 � { p 7 � { 5 C } , x 7 � 23 }} n = � What about the other way round...? • Object diagrams can be partial , e.g. n 1 C : C 5 C : C 1 D : D or 1 C : C 5 C : C 1 D : D x = 23 � we may omit information. • Is the following object diagram partial or complete ? 5 C : C p n 1 C : C 1 D : D p = � p = � x = 23 n = � • If an object diagram – 11 – 2017-06-26 – Sod – • has values for all attributes of all objects in the diagram, and – 12 – 2017-07-03 – main – • if we say that it is meant to be complete then we can uniquely reconstruct a system state � . 39 /51 4 /66

  5. Special Case: Anonymous Objects If the object diagram : C p n 1 C : C : D p = � p = � x = 23 n = � is considered as complete , then it denotes the set of all system states { 1 C 7 � { p 7 � � , n 7 � { c }}} , c 7 � { p 7 � � , n 7 � � } , d 7 � { p 7 � { c } , x 7 � 23 }} where c � D ( C ) , d � D ( D ) , c 6 = 1 C . Intuition : different boxes represent different objects. – 11 – 2017-06-26 – Sod – – 12 – 2017-07-03 – main – 40 /51 5 /66

  6. Content • Proto-OCL • syntax, semantics, • Proto-OCL vs. OCL. • Proto-OCL vs. Software • An outlook on UML • Principles of (Good) Design • modularity, separation of concerns • information hiding and data encapsulation • abstract data types, object orientation • ...by example • Architecture Patterns • Layered Architectures, Pipe-Filter, Model-View-Controller. • Design Patterns – 12 – 2017-07-03 – Scontent – • Strategy, Examples • Libraries and Frameworks 6 /66

  7. Towards Object Constraint Logic (OCL) — “Proto-OCL” — – 12 – 2017-07-03 – main – 7 /66

  8. Motivation C c 0,1 a D A 0,1 • How do I precisely, formally tell my developers that All D -instances having a link to the same C object should have links to the same A . • That is, the following system state is forbidden in the software: a c c a : A : D : C : D : A Note: formally, it is a proper system state . – 12 – 2017-07-03 – Socl – • Use (Proto-)OCL : “Dear developers, please only use system states which satisfy:” ∀ d 1 ∈ allInstances C • ∀ d 2 ∈ allInstances C • c ( d 1 ) = c ( d 2 ) = ⇒ a ( d 1 ) = a ( d 2 ) 8 /66

  9. Constraints on System States C x : Int • Example : for all C -instances, x should never have the value 27 . ∀ c ∈ allInstances C • x ( c ) � = 27 • Proto-OCL Syntax wrt. signature ( T , C , V, atr , F, mth ) , c is a logical variable , C ∈ C : F ::= c : τ C : 2 τ C | allInstances C | v ( F ) : τ C → τ ⊥ , if v : τ ∈ atr ( C ) | v ( F ) : τ C → τ D , if v : D 0 , 1 ∈ atr ( C ) : τ C → 2 τ D , | v ( F ) if v : D ∗ ∈ atr ( C ) | f ( F 1 , . . . , F n ) : τ 1 × · · · × τ n → τ, if f : τ 1 × · · · × τ n → τ : τ C × 2 τ C × B ⊥ → B ⊥ | ∀ c ∈ F 1 • F 2 – 12 – 2017-07-03 – Socl – • The formula above in prefix normal form : ∀ c ∈ allInstances C • � = ( x ( c ) , 27) 9 /66

  10. Semantics • Proto-OCL Types: I � 2 τ C � = D ( C ∗ ) ˙ • I � τ C � = D ( C ) ˙ I � τ ⊥ � = D ( τ ) ˙ ∪ {⊥} , ∪ {⊥} , ∪ {⊥} • I � B ⊥ � = { true , false } ˙ I � Z ⊥ � = Z ˙ ∪ {⊥} , ∪ {⊥} • Functions: • We assume f I given for each function symbol f ( → in a minute). • Proto-OCL Semantics (interpretation function): • I � c � ( σ, β ) = β ( c ) (assuming β is a type-consistent valuation of the logical variables), • I � allInstances C � ( σ, β ) = dom( σ ) ∩ D ( C ) , � σ ( I � F � ( σ, β )) ( v ) , if I � F � ( σ, β ) ∈ dom( σ ) • I � v ( F ) � ( σ, β ) = (if not v : C 0 , 1 ) ⊥ , otherwise � σ ( u ′ )( v ) , if I � F � ( σ, β ) = { u ′ } ⊆ dom( σ ) • I � v ( F ) � ( σ, β ) = (if v : C 0 , 1 ) ⊥ , otherwise • I � f ( F 1 , . . . , F n ) � ( σ, β ) = f I ( I � F 1 � ( σ, β ) , . . . , I � F n � ( σ, β )) , – 12 – 2017-07-03 – Socl –  true , if I � F 2 � ( σ, β [ c := u ]) = true for all u ∈ I � F 1 � ( σ, β )   • I � ∀ c ∈ F 1 • F 2 � ( σ, β ) = false , if I � F 2 � ( σ, β [ c := u ]) = false for some u ∈ I � F 1 � ( σ, β )  ⊥ , otherwise  10 /66

  11. Semantics Cont’d • Proto-OCL is a three-valued logic: a formula evaluates to true , false , or ⊥ . • Example : ∧ I ( · , · ) : { true , false , ⊥} × { true , false , ⊥} → { true , false , ⊥} is defined as follows: x 1 true true true false false false ⊥ ⊥ ⊥ x 2 true false ⊥ true false ⊥ true false ⊥ ∧ I ( x 1 , x 2 ) true false ⊥ false false false ⊥ false ⊥ We assume common logical connectives ¬ , ∧ , ∨ , . . . with canonical 3-valued interpretation. • Example : + I ( · , · ) : ( Z ˙ ∪ {⊥} ) × ( Z ˙ ∪ {⊥} ) → Z ˙ ∪ {⊥} � x 1 + x 2 , if x 1 � = ⊥ and x 2 � = ⊥ + I ( x 1 , x 2 ) = ⊥ , otherwise We assume common arithmetic operations − , /, ∗ , . . . and relation symbols >, <, ≤ , . . . with monotone 3-valued interpretation. • And we assume the special unary function symbol isUndefined : – 12 – 2017-07-03 – Socl – � true , if x = ⊥ , isUndefined I ( x ) = false , otherwise isUndefined I is definite : it never yields ⊥ . 11 /66

  12. Example: Evaluate Formula for System State C 1 C : C σ : x : Int x = 13 ∀ c ∈ allInstances C • x ( c ) � = 27 • Recall prefix notation : ∀ c ∈ allInstances C • � =( x ( c ) , 27) Note : � = is a binary function symbol, 27 is a 0 -ary function symbol. • Example : I � ∀ c ∈ allInstances C • � =( x ( c ) , 27) � ( σ, ∅ ) = true , because... I � � =( x ( c ) , 27) � ( σ, β ) , β := ∅ [ c := 1 C ] = { c �→ 1 C } = � = I ( I � x ( c ) � ( σ, β ) , I � 27 � ( σ, β ) ) = � = I ( σ ( I � c � ( σ, β ) )( x ) , 27 I ) = � = I ( σ ( β ( c ) )( x ) , 27 I ) – 12 – 2017-07-03 – Socl – = � = I ( σ ( 1 C )( x ) , 27 I ) = � = I ( 13 , 27 ) = true ...and 1 C is the only C -object in σ : I � allInstances C � ( σ, ∅ ) = { 1 C } . 12 /66

  13. More Interesting Example C n 1 C : C | σ : x : Int n x = 13 0 .. 1 ∀ c : allInstances C • x ( n ( c )) � = 27 • Similar to the previous slide, we need the value of I � x ( n ( c )) � ( σ, β ) , β = { c �→ 1 C } • I � c � ( σ, β ) = β ( c ) = 1 C • I � n ( c ) � ( σ, β ) = ⊥ since σ ( I � c � ( σ, β ) )( n ) = ∅ � = { u ′ } by rule � u ′ , if I � F � ( σ, β ) ∈ dom( σ ) and σ ( I � F � ( σ, β ))( v ) = { u ′ } I � v ( F ) � ( σ, β ) = (if v : C 0 , 1 ) ⊥ , otherwise • I � x ( n ( c )) � ( σ, β ) = ⊥ since I � n ( c ) � ( σ, β ) = ⊥ by rule – 12 – 2017-07-03 – Socl – � σ ( I � F � ( σ, β )) ( v ) , if I � F � ( σ, β ) ∈ dom( σ ) I � v ( F ) � ( σ, β ) = (if not v : C 0 , 1 ) ⊥ , otherwise 13 /66

  14. More Interesting Example C n 1 C : C | σ : x : Int n x = 13 0 .. 1 ∀ c : C • x ( n ( c )) � = 27 • Similar to the previous slide, we need the value of σ ( σ ( I � c � ( σ, β ) )( n ) ) ( x ) • I � c � ( σ, β ) = β ( c ) = 1 C • σ ( I � c � ( σ, β ) )( n ) = σ ( 1 C )( n ) = ∅ • σ ( σ ( I � c � ( σ, β ) )( n ) ) ( x ) = ⊥ by the following rule: – 12 – 2017-07-03 – Socl – � σ ( u ′ )( v ) , if I � F � ( σ, β ) = { u ′ } ⊆ dom( σ ) I � v ( F ) � ( σ, β ) = (if v : C 0 , 1 ) ⊥ , otherwise 13 /66

  15. Object Constraint Language (OCL) OCL is the same — just with less readable (?) syntax. Literature: (OMG, 2006; Warmer and Kleppe, 1999). – 12 – 2017-07-03 – Socl – 14 /66

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend