lecture 7 class diagrams ii
play

Lecture 7: Class Diagrams II 2016-11-17 Prof. Dr. Andreas Podelski, - PDF document

Software Design, Modelling and Analysis in UML Lecture 7: Class Diagrams II 2016-11-17 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universitt Freiburg, Germany 7 2016-11-17 main Content Rhapsody Demo I:


  1. Software Design, Modelling and Analysis in UML Lecture 7: Class Diagrams II 2016-11-17 Prof. Dr. Andreas Podelski, Dr. Bernd Westphal Albert-Ludwigs-Universität Freiburg, Germany – 7 – 2016-11-17 – main – Content • Rhapsody Demo I: Class Diagrams • Visibility • Intuition • Context , OCL with Visibility • What is Visibility Good For ? • Associations • Overview & Plan • (Temporarily) Extend Signature • From Diagrams to Signatures • What if Things are Missing? – 7 – 2016-11-17 – Scontent – 2 /30

  2. Rhapsody Demo I: Class Diagrams – 7 – 2016-11-17 – main – 3 /30 Class Diagram Semantics Cont’d – 7 – 2016-11-17 – main – 4 /30

  3. Semantical Relevance • The semantics (or meaning) of an extended object system signature S wrt. a structure D is the set of system states � D S . • The semantics (or meaning) of an extended object system signature S is the set of sets of system states wrt. some structure of S , i.e. the set { � D S | D is structure of S } . Which of the following aspects is semantically relevant , i.e. does contribute to the constitution of system states? A class Each attribute has • has a set of stereotypes , • a visibility , • has a name , • a name , a type , • belongs to a package , • a multiplicity , an order , • can be abstract , • an initial value , and • can be active , • a set of properties , – 6 – 2016-11-15 – Sextsig – such as readOnly , ordered , etc. • has a set of attributes , – 7 – 2016-11-17 – Scdsem – • has a set of operations (later). 14 /31 5 /30 What About The Rest? • Classes : • Stereotypes : Lecture 6 • Active : not represented in σ . Later : relevant for behaviour, i.e., how system states evolve over time. • Attributes : • Initial value expression : not represented in σ . Later : provides an initial value as effect of “creation action”. • Visibility : not represented in σ . Later : viewed as additional typing information for well-formedness of OCL expressions and actions. • Properties : such as readOnly , ordered , composite ( Deprecated in the standard.) • readOnly — can be treated similar to visibility . • ordered — not considered in our UML fragment ( → sets vs. sequences). • composite — cf. lecture on associations. – 7 – 2016-11-17 – Scdsem – 6 /30

  4. Visibility – 7 – 2016-11-17 – main – 7 /30 S = ( { Int } , { C, D } , { n : D 0 , 1 , m : D 0 , 1 , The Intuition by Example � x : Int , ξ, expr 0 , ∅�} , { C �→ { n } , D �→ { x, m }} × D n × • ξ x : Int = expr 0 C m 0 , 1 • 0 , 1 n m d 1 : D c : C d 2 : D x = 1 Which of the following two syntactically correct (?) OCL expressions should we consider to be well-typed ? ξ = public ξ = private ξ = protected ξ = package ✔ ✔ later not self C . n . x = 0 ✘ ✘ ? ? ✔ ✔ later not self D . m . x = 0 ✘ ✘ – 7 – 2016-11-17 – Svisityp – ? ? 8 /30

  5. Context S = ( { Int } , { C, D } , { n : D 0 , 1 , m : D 0 , 1 , � x : Int , ξ, expr 0 , ∅�} , { C �→ { n } , D �→ { x, m }} • By example : D n m − x : Int C 0 , 1 0 , 1 self D . x > 0 self D . m . x > 0 self C . n . x > 0 • That is, whether an expression involving attributes with visibility is well-typed depends on the class of the object which “tries to read out the value”. • Visibility is ‘ by class ’ — not ‘by object’. – 7 – 2016-11-17 – Svisityp – 9 /30 Attribute Access in Context Recall : attribute access in OCL Expressions, C, D ∈ C . v ( expr 1 ) : τ C → τ ( v ) • v : T ∈ atr ( C ) , T ∈ T , : τ C → τ D • r 1 : D 0 , 1 ∈ atr ( C ) , r 1 ( expr 1 ) r 2 ( expr 1 ) : τ C → Set ( τ D ) • r 2 : D ∗ ∈ atr ( C ) , New rules for well-typedness considering visibility : • v ( w ) : τ C → T w : τ C , v : T ∈ atr ( C ) , T ∈ T • r 1 ( w ) : τ C → τ D w : τ C , r 1 : D 0 , 1 ∈ atr ( C ) • r 2 ( w ) : τ C → Set ( τ D ) w : τ C , r 1 : D ∗ ∈ atr ( C ) • v ( expr 1 ( w )) : τ C → T � v : T, ξ, expr 0 , P � ∈ atr ( C ) , T ∈ T , expr 1 ( w ) : τ C , w : τ C 1 and C 1 = C , or ξ = + • r 1 ( expr 1 ( w )) : τ C → τ D � r 1 : D 0 , 1 , ξ, expr 0 , P � ∈ atr ( C ) , expr 1 ( w ) : τ C , w : τ C 1 and C 1 = C , or ξ = + – 7 – 2016-11-17 – Svisityp – • r 2 ( expr 1 ( w )) : τ C → Set ( τ D ) � r 2 : D ∗ , ξ, expr 0 , P � ∈ atr ( C ) , expr 1 ( w ) : τ C , w : τ C 1 and C 1 = C , or ξ = + 10 /30

  6. (i) v ( w ) : τ C → T w : τ C , v : T ∈ atr ( C ) , T ∈ T Example (ii) r 1 ( w ) : τ C → τ D w : τ C , r 1 : D 0 , 1 ∈ atr ( C ) (iii) v ( expr 1 ( w )) : τ C → T � v : T, ξ, expr 0 , P � ∈ atr ( C ) , T ∈ T , expr 1 ( w ) : τ C , w : τ C 1 and C 1 = C , or ξ = + (iv) r 1 ( expr 1 ( w )) : τ C → τ D � r 1 : D 0 , 1 , ξ, expr 0 , P � ∈ atr ( C ) , expr 1 ( w ) : τ C , w : τ C 1 and C 1 = C , or ξ = + D n m − x : Int C 0 , 1 0 , 1 • self D . x > 0 • self D . m . x > 0 • self C . n . x > 0 – 7 – 2016-11-17 – Svisityp – 11 /30 The Semantics of Visibility • Observation : • Whether an expression does or does not respect visibility is a matter of well-typedness only . • We only evaluate ( = apply I to) well-typed expressions. → We need not adjust the interpretation function I to support visibility. Just decide: should we take visibility into account yes / no, and check well-typedness by the new / old rules. – 7 – 2016-11-17 – Svisityp – 12 /30

  7. What is Visibility Good For? D n × • − x : Int C 0 , 1 • Visibility is a property of attributes — n : D is it useful to consider it in OCL? : C x = 3 • In other words: given the diagram above, is it useful to state the following invariant (even though x is private in D ) context C inv : n.x > 0 ? It depends . (cf. OMG (2006), Sect. 12 and 9.2.2) • Constraints and pre/post conditions : • Visibility is sometimes not taken into account. To state “global” requirements, it may be adequate to have a “global view”, i.e. be able to “look into” all objects. • But: visibility supports “narrow interfaces”, “information hiding”, and similar good design practices . To be more robust against changes, try to state requirements only in the terms which are visible to a class. Rule-of-thumb : if attributes are important to state requirements on design models, leave them public or provide get-methods (later). • Guards and operation bodies : • If in doubt, yes ( = do take visibility into account). – 7 – 2016-11-17 – Svisityp – Any so-called action language typically takes visibility into account. 13 /30 Associations – 7 – 2016-11-17 – main – 14 /30

  8. Overview • Class diagram (with ternary association) : • Class diagram : C D v : Int A r c : C 0 , 1 a b d : D ∗ w : Int B ∗ 0 , 1 z 1 .. 5 Alternative presentation : Z d C × • ∗ v : Int D c • × 0 , 1 • Signature : extend again to represent • Signature : • association r with S = ( { Int } , { C, D } , { v : Int , d : D ∗ , c : C 0 , 1 } , • association ends a , b , and z { C �→ { v, d } , D �→ { c }} ) (each with multiplicity, visibility, etc.) • Example system state : • Example system state : σ = { 1 A �→ { w �→ 13 } , 1 B �→ ∅ , 1 Z �→ ∅} σ = { 1 C �→ { v �→ 27 , d �→ { 5 D , 7 D }} , λ = { r �→ { (1 A , 1 B , 1 Z ) , (1 A , 1 B , 2 Z ) } } 5 D �→ { c �→ { 1 C }} , 7 D �→ { c �→ { 1 C }}} • Object diagram : – 7 – 2016-11-17 – Sassocplan – d : D : C c c v = 27 : D d • Object diagram : No... 15 /30 Plan • Class diagram (with ternary association) : (i) Study association syntax . (ii) Extend signature accordingly. A r a b w : Int B ∗ 0 , 1 z 1 .. 5 (iii) Define ( σ, λ ) system states with Z • objects in σ (instances of classes) , • links in λ • Signature : extend again to represent (instances of associations) . • association r with • association ends a , b , and z (iv) Change syntax of OCL to (each with multiplicity, visibility, etc.) refer to association ends . (v) Adjust interpretation I accordingly. • Example system state : σ = { 1 A �→ { w �→ 13 } , 1 B �→ ∅ , 1 Z �→ ∅} (vi) ... go back to the special case of C 0 , 1 λ = { r �→ { (1 A , 1 B , 1 Z ) , (1 A , 1 B , 2 Z ) } } and C ∗ attributes. – 7 – 2016-11-17 – Sassocplan – • Object diagram : No... 16 /30

  9. Associations: Syntax – 7 – 2016-11-17 – main – 17 /30 UML Association Syntax Oestereich (2006) Vererbung Attributierte Assoziation Klasse1 Klasse2 Klasse1 Klasse2 Assoziations- Assoziation klasse Klasse1 Klasse2 Aggregation gerichtete Assoziation Teil Klasse1 Klasse2 Ganzes Komposition Existenz- abhängiges Teil qualifizierte Assoziation Klasse1 Klasse2 Qualifizierer Mehrgliedrige Assoziation Klasse1 Klasse2 Realisierung Klasse1 Klasse2 Klasse3 Unab- Abhängigkeit Abhängige hängige Klasse Klasse Multiplizität Leserichtung Schnittstelle «Stereotyp» Anbieter Nutzer Beziehungsname * {ordered} 1 Klasse1 Klasse2 Sichtbarkeit rolle – 7 – 2016-11-17 – Sassocsyn – rolle 18 /30

Recommend


More recommend