Presentation is loading. Please wait.

Presentation is loading. Please wait.

A Formal Descriptive Semantics of UML Lijun Shan Dept of Computer Science National University of Defense Technology, Changsha, China Hong Zhu Department.

Similar presentations


Presentation on theme: "A Formal Descriptive Semantics of UML Lijun Shan Dept of Computer Science National University of Defense Technology, Changsha, China Hong Zhu Department."— Presentation transcript:

1 A Formal Descriptive Semantics of UML Lijun Shan Dept of Computer Science National University of Defense Technology, Changsha, China Hong Zhu Department of Computing and Electronics Oxford Brookes University, Oxford, UK

2 Outline What is descriptive semantics? The concept and motivation How to specify descriptive semantics? The formal framework Mappings from diagrams to first order logic (FOPL) Application to UML class, interaction and state machine diagrams Application of descriptive semantics to consistency checking of UML models Conclusion

3 What is the meaning of UML diagrams? The system has two classes called Member and Book, (There are two types of objects called member and book ) There is an association between them, which is called Borrow ( Members can borrow books ) The upper limit of borrowing is 10 (Each member can only borrow up to 10 books at any time) The upper limit for a book to be borrowed is 1 (Each book can only be borrowed by at most 1 member at any time) Member Book Borrow Library system Instances of the class Member Instances of the class Book

4 Semantics of modelling languages A model is a set of statements about some system under study [Seidwitz, 2003] The semantics of a modelling language is the satisfaction relationship between a model and a system. s m Software model, and models in all scientific disciplines A system in the subject domain D, i.e. universe of systems that the language is modelling. A well-formed model in the modelling language. s is an instance of the model m, i.e. s satisfies the statements of the model m

5 Two types of semantics Descriptive semantics Describe the system based on a set of basic concepts, such as class, association multiplicity upper bound, etc. Example: The system has two classes called Member and Book Functional semantics Define how the system functions at run time. Example: There are two types of objects called members and books. Existing work on UML semantics often occurs as a combination of them. They are at object level. Example: x.(Member(x) ||{y | Book(y) Borrows(x,y)}|| 10) Class(Member), Class(Book), Asssociation(Borrows), …

6 Difficulties in the formalisation of UML Interpretation in different subject domains: One model can be interpreted in several different subject domains Library system model: When interpreted on the subject domain of real world systems, the library of Oxford Brookes University is an instance When interpreted on the computer software, … Extension with new concepts: New basic concepts and constructs can be introduced through extension facilities, such as introduce new stereo types in profile definitions Uses in different context: One model may have different meanings in different context

7 Example: Which of the following programs is the correct semantics of the model on the right? There are exactly three different classes such that …; There are at least three different classes such that …; Which of the following programs can be considered as satisfying the model? Member StaffStudent class Member { … } class Staff extends Member {…} Class Student extends Member {…} class MScStudent extends Student {…} class Member { public enum MemberType { Staff, Student } public MemberType TypeOfMember; … } UML gives no definition on this issue!

8 Overview of our approach This is consistent with the theory of institution proposed by Goguen and Burstall (1992) for formal specification languages.

9 The formal framework Definition 1. (Semantics of a modelling language) A formal semantic definition of a modelling language consists of the following elements. A signature Sig, which defines a formal logic system; A set Axm D of axioms about the descriptive semantics, which is in the formal logic system defined by Sig; A set Axm F of axioms about the functional semantics, which is also in the formal logic systems defined by Sig; A mapping T from models to a set of formulas in the formal logic system defined by Sig. The formulas are the statements for the descriptive semantics of the model; A mapping H from models to a set of formulas in the formal logic system defined by Sig. The formulas represent the hypothesis about the context in which the descriptive semantics is interpreted.

10 Definition 2. (Semantics of a model) Given a semantics definition of a modelling language as in Definition 1, the semantics of a model M under the hypothesis H, written Sem H (M), is defined as follows. Sem H (M) = Axm D Axm F T(M) H(M) where T(M) and H(M) are the sets of statements obtained by applying the semantic mappings T and H to model M, respectively. The descriptive semantics of a model M under the hypothesis H, written DesSem H (M), is defined as follows. DesSem H (M) = Axm D T(M) H (M)

11 Satisfaction relation Definition 4. (Subject domain) A subject domain Dom of signature Sig with an interpretation Eva is a triple, where D is a collection of systems on which the formulas of the logic system defined by Sig can be evaluated according to a specific evaluation rule Eva. The value of a formula f evaluated according to the rule Eva in the context of system s D, written as Eva(f, s), is called the interpretation of the formula f in s. We write s|= Eva f, if a formula f is evaluated to true in a system s D, i.e. s|= Eva f iff Eva(f, s)= true. Definition 5. (Satisfaction of a model) Let Sig be a given signature and Dom a subject domain of Sig. A system s in D satisfies a model M according to a semantic definition Sem H (M) if s|= Sem H (M), i.e. for all formulas f in Sem H (M), s|=f.

12 Signature Mapping The signature mapping S from a metamodel M to a signature = S (M) is defined by a set of signature rules so that statements representing the descriptive semantics of models are -sentences of first order predicates. Signature Rules S1. For each metaclass named MC in the metamodel, we define a unary atomic predicate MC(x). S2. For each metaassociation from a metaclass X to a metaclass Y in a metamodel, if MA is the association end on the Y side of the metaassociation, a binary predicates MA(x, y) is defined. S3. For each metaattribute named MAttr of type MT in a metaclass MC in a metamodel, a unary function MAttr(x) is defined with domain MC and range MT. S4. For each enumeration value EV given in an enumeration metaclass ME in a metamodel, a constant EV is defined.

13 A Simplified Metamodel of Class Diagram

14 Example: Signature elements: unary predicates : Class(x), Classifier(x), Generalisation(x) binary predicates: general(x, y) specific(x, y) Metamodel

15 Translation mapping Translation mapping is defined by a set of translation rules that generate formulas in the signature from a UML model M. Translation Rules T1: Classification of elements. For each identifier id of concrete type MC, a formula in the form of MC(id) is generated. T2: Properties of elements. For each element a in the model and every applicable function MAttr that represents a metaattribute MAttr, a formula in the form of MAttr(a)=v is generated, where v is as value on the property. T3: Relationships between elements. For each pair (e 1, e 2 ) of elements related by relationship R, a formula in the form of R(e 1, e 2 ) is generated to specify the relationship by applying binary predicate R(x 1, x 2 ).

16 Example: Signature elements: unary predicates : Class(x), Classifier(x), Generalisation(x) binary predicates general(x, y) and specific(x, y) Metamodel Model Statements of the model: Class(Woman), Class(Person), Generalisation(wp) specific(wp, Woman), general(wp, Person)

17 Interpretation in different contexts The context in which a model is interpreted can be specified as hypothesis. A hypothesis can be defined as a rule that maps from a model to formulas in the signature. Hypothesis Rules H1: Distinguishability of elements. A hypothesis that the elements of type MC in the model are all different from each other can be generated as formulas in the form of e i e j, for i j {1,2,…,k}. H2: Completeness of elements. A hypothesis on the completeness of elements of type MC can be generated as a formula in the following form. x. MC(x) (x = e 1 ) (x = e 2 ) … (x = e k ) H3: Completeness of relations. A hypothesis on the completeness of relation R in the model can be generated as a formula in the following form. x 1,x 2.R(x 1,x 2 ) ((x 1 =e 1,1 ) (x 2 =e 1,2 )) ((x 1 = e 2,1 ) (x 2 = e 2,2 )) … ((x 1 = e n,1 ) (x 2 = e n,2 ))

18 Axiom mapping It is defined by a set of rules that maps metamodel to - sentences as axioms of the models. These rules represents the semantics of OO concepts applied to meta-modelling. Axiom rules: A1: Completeness of classification. Let MC 1, MC 2, …, MC n be the set of concrete metaclasses in a metamodel. We have an axiom x. MC 1 (x) MC 2 (x) … MC n (x) A2: Disjointness of classification. Let MC 1, MC 2, …, MC n be the set of concrete metaclasses in a metamodel. For each pair of different concrete metaclasses MC i and MC j, i j, we have an axiom x. MC i (x) ¬ MC j (x). A3: Logical implication of inheritance. For a generalisation relation from metaclass MA to MB in a metamodel, we have an axiom x. MA(x) MB(x).

19 Strict metamodelling principle Axiom rules also contain hypothesis on the uses of class diagrams as metamodels, such as the strict meta-modelling principle, which is to ensure that a metamodel is a well-defined abstract syntax of modelling language. Strict Metamodelling: In an n-level modelling architecture M 0, M 1, …, M n, every element of an M m -level model must be an instance-of exactly one element of an M m+1 -level model, for all 0 m < n-1, and any relationship other than the instance-of relationship between two elements X and Y implies that level(X) = level(Y).

20 Axiom Rules (Continue) A4: Completeness of specialisations. Let MA be a metaclass in a metamodel and MB 1, MB 2, …, MB k be the set of metaclasses specialising MA. We have an axiom x. MA(x) MB 1 (x) MB 2 (x) … MB k (x). A5: Types of parameters of predicates. For each binary predicate MA(x, y) derived from an association from metaclass MC 1 to MC 2 in a metamodel, we have an axiom x, y. MA(x, y) MC 1 (x) MC 2 (y). A6: Domain and range of functions. For each function MAttr(x) derived from a metaattribute MAttr of type MT in a metaclass MC, we have an axiom x,y. MC(x) (MAttr(x) = y) MT(y). A7: Multiplicity of binary predicate. For each binary predicate MA(x, y) derived from an association from metaclass MC 1 to MC 2 in a metamodel, let Mul be the multicity value specified on the association end MA, we have axioms in the following form. If Mul = 0..1: x, y, z. MC 1 (x) MA(x, y) MA(x, z) (y = z) If Mul = 1 or unspecified: x. MC 1 (x) y. MA(x, y) and x, y, z. MC 1 (x) MA(x, y) MA(x, z) (y = z) If Mul = 1..*: x. MC 1 (x) y. MA(x, y) If Mul = 2..*: x. MC 1 (x) y, z. MA(x, y) MA(x, z) (y z) If Mul = 0..2: x, y, z, u. MC 1 (x) MA(x, y) MA(x, z) MA(x, u) (y = z) (y = u) (u = z)

21 Axiom Rules (continue) A8: Multiplicity of function. For each function MAttr(x) derived from a metaattribute MAttr of type MT in a metaclass MC, let Mul be the multicity value of the metaattribute MAttr, we have axioms: If Mul = 0..1: x, y, z. MC(x) (MAttr(x) = y) (MAttr(x) = z) -> (y = z) If Mul = 1: x. MC(x) -> y. (MAttr(x) = y) and x, y, z. MC(x) (MAttr(x) = y) (MAttr(x) = z) -> (y = z) If Mul = 1..*: x. MC(x) -> y. (MAttr(x) = y) A9: Distinguishability of the literal constants. For each pair of different literal values a and b of an enumeration type, we have an axiom a b. A10: Type of the literal constants. For each enumeration value a defined in an enumeration metaclass ME, we have an axiom in the form of ME(a) stating that the type of a is ME. A11: Completeness of the enumeration. An enumeration type only contains the listed literal constants as its values, hence for each enumeration metaclass ME with literal values a1, a2, …, ak, we have an axiom in the form of x. ME(x) -> (x = a1) (x = a2) … (x = ak). Axiom Rule 12: Well-formedness rules. For each WFR formally specified in OCL, we have a corresponding axiom in the first order language.

22 Semantics of Interaction and State Machine Same signature, axiom and formula mappings are applied to the meta-models of UML state machine and interaction diagrams. Additional Axiom Rules for inter-metamodel connections Axiom Rules A10: Cross metamodel association and inheritance. For each cross metamodel inheritance from metaclass MA to external metaclass MB, we have an axiom in the form of x. MA(x) -> MB(x). A2: Completeness of specialisations across metamodels. Let MA be a metaclass depicted in two metamodels MM1 and MM2. Let metaclasses MB 1, MB 2, …, MB k be the set of metaclasses that specialise MA in metamodel MM 1, and MC 1, MC 2, …, MC p be the set of metaclasses that specialise MA in metamodel MM 2. We have the following axiom when a model is defined by MM 1 and MM 2. x. MA(x) -> MB 1 (x) … MB k (x) MC 1 (x) … MC p (x)

23 A Simplified Metamodel of Interaction Diagram

24 A Simplified Metamodel of State Machine

25 The Tool LAMBDES LAMBDES stands for Logic Analyser of Model/Metamodel Based on Descriptive Semantics

26 Applications of Descriptive Semantics Consistency checking of UML models Validation of consistency constraints for UML models Consistency checking of UML meta-models Conformance checking of designs to design patterns Consistency checking of specification of design patterns Definition 3. (Properties of a model) Let Sem H (M) be the semantics of a model M. M has a property P (represented as a formula in the logic system defined by Sig) under the semantics definition Sem H (M) and the hypothesis H, if and only if Axm D Axm F T(M) H(M) P in the formal logic system. Similarly, we say that M has a property P in descriptive semantics, if and only if Axm D T(M) H(M) P in the formal logic system.

27 Consistency checking of UML models Definition 6. (Logical consistency) Let Sem H (M) = Axm D Axm F T(M) H(M) be the semantics of a model M. Model M is said to be logically inconsistent in the semantic definition Sem H (M) if Sem H (M)|-false; otherwise, we say that the model is logically consistent. Definition 7. (Consistent interpretation in a subject domain) Let Dom= be a subject domain as defined in Definition 4. The interpretation of formulas in signature Sig is consistent with first order logic if and only if for all formulas q and p 1, p 2, …, p k that p 1, p 2, …, p k |- q, and for all systems s in D that Eva(pi, s) =true for i=1,2,…, k, we always have Eva(q, s) =true.

28 Validity of consistency checking Theorem 1. (Unsatisfiability of inconsistent model) A model M that is logically inconsistent in the semantic definition Sem H (M) is not satisfiable on any subject domain whose interpretation of formulas is consistent with first order logic. Inconsistent model => it cannot be implemented (not satisfiable) Consistency model => not necessarily implementable Other issues effect satisfiability: Property of the subject domain: e.g. whether the programming language is powerful enough to implement Non-logic property of the model: e.g. whether the system is feasible

29 Validation of consistency constraints Consistency constraints: Logic statements about models, e.g. a life line must represent an instance of a class x, y, z. Lifeline(x) represent(x,y) type(y, z) Class(z) Definition 8. (Consistency w.r.t. consistency constraints) Given a set of consistency constraints C={c 1, c 2, …, c n }, the consistency of a model M with respect to the constraints C under the semantics definition Sem H (M) is the consistency of the set U = Sem H (M) C of formulas. In particular, we say that a model fails on a specific constraint c k, if Sem H (M) is consistent, but Sem H (M) {c k } is not. Results of experiments: A number of sample UML models were checked to be consistent. Mutants of the models were checked and inconsistency in mutants were detected.

30 Definition of validity and effectiveness Definition 9. (Validity of consistency constraints) Let Axm D and Axm F be the sets of axioms for descriptive semantics and functional semantics, respectively. A set C={c 1, c 2, …, c n } of consistency constraints is descriptively valid if Axm D C is logically consistent. The set C of consistency constraints is functionally valid Axm D Axm F C is logically consistent. Definition 10. (Effectiveness of consistency constraints) Let A be a set of semantics axioms. A set C={c 1, c 2, …, c n } of consistency constraints is logically ineffective with respect to the set A of axioms if A C. Results of Experiments: A set of 5 consistency constraints were validated by using LAMBDES tool. They were proved valid and effective.

31 Consistency checking of meta-models Definition 11 (Inconsistency of meta-model). A meta-model M is inconsistent if Axm D (M) is logically inconsistent. Experiments: Subjects: Simplified UML, UML 2.0 metamodel, AspectJ profile Findings: Simplified metamodel: consistent UML 2.0: 16 inconsistencies due to voilation of strict meta-modelling 1 inconsistently as abstract and concrete metaclasses in different metamodel class diagrams. AspectJ: Incomplete definition of 7 meta-classes 2 inconsistency due to violation of strict meta-modelling

32 Conclusion Separation of functional semantics from descriptive semantics can simplify the formal semantic definition of UML and it is scalable Applicable for all types of diagrams defined in meta-model uniformly Applicable to multiple views defined by multiple meta-models, and addressed the extendability issues Addressed the issue due to flexibility in the uses of modelling language in different development context Addressed the issue for different interpretation of modelling languages in different subject domains Reasoning about models in first order logic can be feasible and useful in model drive software development Can be automated by tools such as LAMBDES + SPASS + StarUML Can reason about properties that are not possible for semantics at object level, such as The validation of consistency constraints, The consistency of meta-model, etc. The conformance of designs to patterns,

33 Future work Further development of the axioms for functional semantics; Theoretical analysis of the logic properties of the semantics definition Soundness of the rules: yes Consistency of the rules: yes Completeness of the rules: In what sense? How to prove? Case studies on reasoning about other properties of designs, such as Platform specific models, platform independence, etc. Transformation of models,


Download ppt "A Formal Descriptive Semantics of UML Lijun Shan Dept of Computer Science National University of Defense Technology, Changsha, China Hong Zhu Department."

Similar presentations


Ads by Google