Top Banner
A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology
51

A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Mar 28, 2015

Download

Documents

Jayden Spencer
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

A Formal Descriptive Semantics of UML and Its Applications

Hong ZhuDepartment of Computing and ElectronicsSchool of Technology

Page 2: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Acknowledgement

The work reported here is based on the outcomes of the collaborative research with Dr. Ian Bayley, Oxford Brookes University, UK Ms. Lijun Shan, National University of Defense

Technology, China (visitor to Oxford Brookes University funded by China Scholarship Council)

Mr. Richard Amphlett, Oxford Brookes University, UK (Funded by Reinvention Centre as Undergraduate Research Student Scholarship)

Page 3: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Outline

What is descriptive semantics? The concept and motivation

How to specify descriptive semantics? The formal framework Formal definition of mappings from diagrams to first order

logic (FOPL) Application to UML class, interaction and state machine

diagrams The relationships between descriptive semantics and

functional semantics Why descriptive semantics are important and useful?

Implementation of the semantics and the tool LANBDES Applications in formal reasoning about models in FOPL

Page 4: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

What is the meaning of UML diagrams? The system has two classes called

Member and Book, (There are two types of objects called members and books)

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

0..10

0..1

Instances of the class Member

Instances of the class Book

Page 5: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Semantics of modelling languages

‘A model is a set of statement 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

Page 6: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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 funct

ions 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.

Example: Each instance of the Book class can only be borrowed by at most 1 member at any time.

Page 7: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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

Page 8: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Example: Which of the following is the correct

semantics of the model on the left? 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 satisfied the model?

Member

Staff Student

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!

Page 9: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Overview of our approach

This is consistent with the theory of institute proposed by Goguen and Burstall (1992) for formal specification languages.

Page 10: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

The formal frameworkDefinition 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 AxmD of axioms about the descriptive semantics, which is

in the formal logic system defined by Sig; A set AxmF 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.

Page 11: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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 SemH(M), is defined as follows.

SemH(M) = AxmD AxmF 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 DesSemH(M), is defined as follows.

DesSemH(M) = AxmD T(M) H (M)

Page 12: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Satisfaction relation

Definition 4. (Subject domain)

A subject domain Dom of signature Sig with an interpretation Eva is a triple <D, Sig, Eva>, 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 sD, written as Eva(f, s), is called the interpretation of the formula f in s. We write s|=Evaf, if a formula f is evaluated to true in a system sD, i.e. s|=Evaf 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 SemH(M) if s|= SemH(M), i.e. for all formulas f in SemH(M), s|=f.

Page 13: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

A Simplified Metamodel of Class Diagram

MultiplicityElement

ValueSpecification

+upperValue+lowerValue

TypedElement

Type+type

Classifier

+isAbstract: BooleanGeneralisation

+general

DirectedRelationshipFeature

+isStatic: Boolean

StructuralFeature BehaviouralFeature

Parameter

+direction: ParameterDirectionKind

+ownedParameter

Operation ClassProperty

+aggregation: AggregationKind

+ownedAttribute0..1*

Association

+memberEnd2..*

+ownedOperation

0..1*

Relationship

ParameterDirectionKind<<enumeration>>

+in+out+inout+return

AggregationKind<<enumeration>>

+none+shared+composite

Boolean<<enumeration>>

+t+f

DataType

Signal

+specific

Interface

+ownedOperation

+ownedAttribute

NamedElement

VisibilityKind<<enumeration>>

+public+private+protected+package

+associateTo

Page 14: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Signature MappingThe 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 RulesS1. 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.

Page 15: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Example:

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

Classifier GeneralisationClass

+general

+specific

PersonWoman

Metamodel

Page 16: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Translation mappingTranslation 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 a’s value on the property. T3: Relationships between elements.

For each pair (e1, e2) of elements related by relationship R, a formula in the form of R(e1, e2) is generated to specify the relationship by applying binary predicate R(x1, x2).

Page 17: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Example:

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

Classifier GeneralisationClass

+general

+specific

PersonWoman

Metamodel

Model

Statements of the model: Class(Woman), Class(Person), Generalisation(wp) specific(wp, Woman), general(wp, Person)

Classifier GeneralisationClass

+general

+specific

PersonWoman

Page 18: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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 ei ej, for ij {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 = e1) (x = e2) … (x = ek) 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.

x1,x2.R(x1,x2)((x1=e1,1)(x2=e1,2))((x1= e2,1) (x2= e2,2))

… ((x1= en,1) (x2= en,2))

Page 19: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Definition of functional semantics

Functional semantics defines the basic concepts of object orientation

Our approach: axioms in second order predicate logic

For example, If class A inherits class B, every instance of A is also

an instance of BClass(A) Class(B) Inherits(A,B) x (A(x) B(x))

Predicates at model level in descriptive semantics.

A(x): object x is an instance of class A.It is a predicate at object level.

Page 20: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Object and classAxiom 1: Every object must be an instance of a class.

x (Object(x) C.(Class(C) C(x)))

Axiom 2: Every attribute declared in a class is a property of the class.

OwnedAttribute(C, x) HasAttribute(C, x)

Axiom 3: Every operation declared in a class is an operation of the class

OwnedOperation(C, x) HasOperation(C, x)

Notation: Every class C in the system is represented as a predicate C(x) such that C(a) is true if and only if a is an instance of class C.

This formula is now second order because C is a qualified variable range over predicates.

Page 21: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

InheritanceAxiom 4: If class A inherits class B, every instance of A is

also an instance of B.Class(A) Class(B) Inherits(A,B) x (A(x) B(x))

Axiom 5: If class A inherits class B, every attribute of B is also an attribute of AClass(A) Class(B) Inherits(A,B) x (Property(x) HasAttri

bute(B, x) HasAttribute(A,x))

Axiom 6: If class A inherits class B, every operation of B is also an operation of AClass(A) Class(B) Inherits(A,B) x (Operation(x) HasOp

eration(B, x) HasOperation(A,x))

Inherits(A,B) = x (Generalisation(x) specific(x, A) general(x, B)

Page 22: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Re-definition and PolymorphismLet class A inherits class B. Axiom 7: If A declares attribute a with type TA, then the type of attribute a is TA regardless what is defined in class B.

Class(A), Class(B), Inherits(A,B), HasAttribute(A, a), OwnedAttribute(A,a), Type(a,TA)

CurrentType(a, A, TA)Axiom 8: If class A does not declare attribute a, but inherited attribute from B, then the type of attribute a is as in B.

Class(A), Class(B), Inherits(A,B), HasAttribute(A, a), OwnedAttribute(A,a)

( CurrentType(a, B, TB) CurrentType(a, A, TB)

Notation: CurrentType(a, A, B) means the current type of attribute a in class A is B. Note: There are similar axioms for operations.

Page 23: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Abstract class

Axiom 9: If class A is abstract, for every instance x of A, there must be a subclass B of A such that x is an instance of B.Class(A) IsAbstract(A)

x.(A(x) B.(Class(B)Inherits(B,A) B(x)))

Notation: IsAbstract(C) == IsAbstract(C, True)

Page 24: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Attribute and associationAxiom 10:

Class(A) HasAttribute(A, a) CurrentType(a, A, B) (x, y. a(x, y) A(x) B(y))

Axiom 11: Class(A) Class(B) Association(a) memberEnd(a, Ea) CurrentType(Ea, A) memberEnd(a, Eb) CurrentType(Eb, B) (x, y. Eb(x, y) A(x) B(y)) (x, y. Ea(x, y) B(x) A(y)) A B

aEa Eb

A

a: B

Notation: For any attribute or association a, a(x,y) denotes x.a=y .This is to keep notation consistent with the notation,e.g. Association(A,B) used in descriptive semantics derived from metamodel.

Page 25: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Multiplicity

Axiom 12: Multiplicity of associationAssociation(a) memberEnd(a, Ea) type(Ea, A) membe

rEnd(a, Eb) type(Eb, B) upperValue(Eb, m) lowerValue(Eb, n) (x. A(x) n||{y | Eb(x, y) }||m)

Axiom 13: Multiplicity of attributesClass(A) ownedAttribute(A, a) type(a, B) upperValue(

a, m) lowerValue(a, n) (x. A(x) n||{y | a(x, y) }||m)

Page 26: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Enumeration

Axiom 14: Distinguishability of the literal constants

Enumeration(A) ownedLiteral(A, v1) ownedLiteral(A, v2)

(Identifier(v1) Identifier(v2 ) (v1 v2))

Axiom 15: Type of the literal constants Enumeration(A) ownedLiteral(A, v) A(v)

Axiom 16: Completeness of the enumeration EnumClass(A) (x.( A(x) ownedLiteral(A, x)))

Page 27: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Whole-part relationships

Axiom 17: Composite relation

(Class(A) Class(B) Association(C) memberEnd(C, b) type(b, B) aggregation(b, composite) )x. (B(x) !y.(A(y) b(x,y))

A B

C

+b+a

Page 28: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Combination of functional and descriptive semantics

Applying functional semantics to models ‘Ordinary’ semantics in first order logic,

i.e. the properties that objects of the system at run time must satisfy

For example, [Berardi, Cal and Calvanese, 2005], [Kaneiwa and Satoh, 2006], etc.

Applying functional semantics to metamodel Axioms of models,

i.e. the properties satisfied by all models

Page 29: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Apply functional semantics to model: Example

Class(Woman), Class(Person), Generalisation(wp), specific(wp, Woman), general(wp, Person) ,

A, B (Class(A) Class(B) Inherits(A,B) x (A(x) B(x)))

x (Woman(x) Person(x))

where Inherits(A,B) =

x (Generalisation(x) specific(x, A) general(x, B)

Classifier GeneralisationClass

+general

+specific

PersonWoman Descriptive semantics

Functional semanticsObject level semantics

Page 30: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Apply functional semantics to metamodelClassifier GeneralisationClass

+general

+specific

PersonWoman

MetaClass(Class), MetaClass(Classifier), MetaGeneralisation(cc),

specific(cc, Class), general(cc, Classifier) ,

A, B.(Class(A) Class(B) Inherits(A,B) x (A(x) B(x)))

x (Class(x) Classifier(x)) where Inherits(A,B) =

x (MetaGeneralisation(x) specific(x, A) general(x, B)

Descriptive semantics applied to metamodel

Functional semantics

Axiom of models

Page 31: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Implementation of functional semanticsThe functional semantics for the OO concepts used in UML

class diagram are defined as a set of rules that maps from class diagram (metamodel) to axioms (formulas of the -sentences) and implemented directly.

Axiom rules:A1: Completeness of classification.

Let MC1, MC2, …, MCn be the set of concrete metaclasses in a metamodel. We have an axiom x. MC1(x) MC2(x) … MCn(x)A2: Disjointness of classification.

Let MC1, MC2, …, MCn be the set of concrete metaclasses in a metamodel. For each pair of different concrete metaclasses MCi and MCj, ij, we have an axiom x. MCi(x) ¬ MCj(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).

Corresponding to Axiom 4 of functional semantics

Page 32: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Axiom Rules (Continue)

A4: Completeness of specialisations.

Let MA be a metaclass in a metamodel and MB1, MB2, …, MBk be the set of metaclasses specialising MA. We have an axiom x. MA(x) MB1(x) MB2(x) … MBk(x).

A5: Types of parameters of predicates.

For each binary predicate MA(x, y) derived from an association from metaclass MC1 to MC2 in a metamodel, we have an axiom x, y. MA(x, y) MC1(x) MC2(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 MC1 to MC2 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. MC1(x) MA(x, y) MA(x, z) (y = z)If Mul = 1 or unspecified: x. MC1(x) y. MA(x, y) and

x, y, z. MC1(x) MA(x, y) MA(x, z) (y = z)If Mul = 1..*: x. MC1(x) y. MA(x, y)If Mul = 2..*: x. MC1(x) y, z. MA(x, y) MA(x, z) (y z)If Mul = 0..2: x, y, z, u. MC1(x) MA(x, y) MA(x, z) MA(x, u)

(y = z) (y = u) (u = z)

Corresponding to Axiom 10

Corresponding to Axiom 11

Corresponding to Axiom 12

Page 33: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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 ofx. 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.

Corresponding to Axiom 13

Corresponding to Axiom 14

Corresponding to Axiom 15

Corresponding to Axiom 16

Page 34: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Strict metamodelling principle Axiom rules also contain ‘hypothesis’ on the uses of class diagra

ms 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 M0, M1, …, Mn, every element of an Mm-level model must be an instance-of exactly one element of an Mm+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).

Corresponding to axiom rules A1, A2 and A4.

Page 35: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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 connectionsAxiom 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 MB1, MB2, …, MBk be the set of metaclasses that specialise MA in metamodel MM1, and MC1, MC2, …, MCp be the set of metaclasses that specialise MA in metamodel MM2. We have the following axiom when a model is defined by MM1 and MM2.

x. MA(x) -> MB1(x) … MBk(x) MC1(x) … MCp(x)

Page 36: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

A Simplified Metamodel of Interaction Diagram

Interaction

Lifeline Message

+lifeline +message

ConnectableElement

+represents

MessageEvent

SendOperationEvent SendSignalEventOperation (from Kernel) Signal (from Kernel)

+operation +signal

+event

+sender

+receiver+after

Behaviour BehaviouralFeature (from Kernel)Classifier(from Kernel)

+specification

+context

TypedElement(from kernel)

Page 37: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

A Simplified Metamodel of State Machine

StateMachine

ProtocolStateMachine Vertex

StatePseudoState

+kind: PseudostateKind

Transition

+vertex

+transition

+source

+target

Trigger Constraint

+trigger +guard

ProtocolConformance

DirectedRelationship(from Kernel)

+generalMachine+specificMachine

Behaviour (from Interaction)

+exit +doActivity+entry

+effect

PseudostateKind<<enueration>>

+initial+final+deepHistory+shallowHistory+join+fork+junction+choice

BehaviourStateMachine

StateBehaviour

Page 38: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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

User InterfaceLAMBDES

Logic system for metamodel

Modelling tool StarUML

Axiom Generator

Metamodel

Metamodel in XMI

Theorem prover SPASS

Inference result

Statements

Model

Model in XMI

Signature Generator

Formula Generator

Signature Axioms

Proof Goal

Hypothesis

Modelling Context

Hypothesis Generator

Domain Generator

Auxiliary constants &

formulas

Conjecture Generator

Conjecture

Logic system for model

Design Pattern Specification

Design Pattern Spec

Repository

Page 39: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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 SemH(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 SemH(M) and the hypothesis H, if and only if AxmDAxmFT(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 AxmDT(M) H(M) P in the formal logic system.

Page 40: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Consistency checking of UML models

Definition 6. (Logical consistency)

Let SemH(M) = AxmD AxmF T(M) H(M) be the semantics of a model M. Model M is said to be logically inconsistent in the semantic definition SemH(M) if SemH(M)|-false; otherwise, we say that the model is logically consistent.

Definition 7. (Consistent interpretation of formulas in a subject domain)

Let Dom=<D, Sig, Eva> 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 p1, p2, …, pk that p1, p2, …, pk |- 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.

Page 41: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Validity of consistency checkingTheorem 1. (Unsatisfiability of inconsistent model)

A model M that is logically inconsistent in the semantic definition SemH(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

Page 42: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

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={c1, c2, …, cn}, the consistency of a model M with respect to the constraints C under the semantics definition SemH(M) is the consistency of the set U = SemH(M) C of formulas. In particular, we say that a model fails on a specific constraint ck, if SemH(M) is consistent, but SemH(M) {ck} is not.

Results of experiments:• A number of sample UML models were checked to be

consistent.• Mutants of the models were checked and detected inconsistency

in mutants.

Page 43: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Definition of validity and effectiveness

Definition 9. (Validity of consistency constraints)

Let AxmD and AxmF be the sets of axioms for descriptive semantics and functional semantics, respectively. A set C={c1, c2, …, cn} of consistency constraints is descriptively valid if AxmDC is logically consistent. The set C of consistency constraints is functionally valid AxmDAxmFC is logically consistent. Definition 10. (Effectiveness of consistency constraints)

Let A be a set of semantics axioms. A set C={c1, c2, …, cn} 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.

Page 44: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Consistency checking of meta-modelsDefinition 11 (Inconsistency of meta-model).

A meta-model M is inconsistent if AxmD(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-classes2 inconsistency due to violation of strict meta-modelling

Page 45: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Conformance of designs to patterns Patterns are meta-models (rather than models)

A pattern specifies a set of models that have common structural and behavioural properties

A pattern can be specified as a predicate on models in first order logic (Bayley and Zhu 2007, 2008)

Page 46: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Translation of pattern specification A specification of design pattern is translated into a

specification of systems in sig-formulasTemplate Method Specification

formula(exists([%Components: xAbstractClass, xTemplateMethod, xOthers ], and(%Static conditions: Class(xAbstractClass), ownedOperation(xAbstractClass, xTemplateMethod), ownedOperation(xAbstractClass,xOthers), isLeaf(xTemplateMethod,bTrue), not(equal(xTemplateMethod,xOthers)), isLeaf(xOthers,bFalse)%Dynamic conditions: callsHook(xTemplateMethod,xOthers)))).

Page 47: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Validity of conformance checking

Definition 12 (Correctness of translation)Let p be a predicate on models, p' be a predicate on systems. The predicate p' is a correct translation of p, if for all models m, we have that

m |- p iff sD. (s |= (Sem(m) p’).

TheoremLet P be a pattern and Spec(P) be a specification of the pattern. Suppose that Spec'(P) is a correct translation of Spec(P). For all models m, if Sem(m) Spec'(P) is true in FOL, then, for all systems s D, s |= m implies s |= Spec'(P).

Page 48: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Experiments Specification of patterns:

23 design patterns in GoF book are specified in first order logic on models Translation:

The specifications are translated into first order logic in LAMBDES syntax Experiment 1: checking specifications Consistency

23 specifications of patterns were checked for consistency with the axioms Results: all specification are consistent

Experiment 2: Testing conformance checking ability 23 designs represented in UML diagrams are created according to GOF; Each design is checked against all 23 patterns using LAMBDES Results:

100% recognition of designs as instances of intended pattern 22% of false positive recognitions (including time-out, which is 5%)

Experiment 3: Testing modelling tool’s correctness 23 design created using StarUML templates Each design is checked against all 23 patterns using LAMBDES Results: 61% is not recognised, Overall fault detecting rate: 81%

Page 49: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Conclusion and comparison Separation of functional semantics from descriptive semantics ca

n 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 addre

ssed 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 u

seful 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 le

vel, such as The conformance of designs to patterns, The validation of consistency constraints, The consistency of meta-model, etc.

Page 50: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

Future work Further development of the axioms in second order

predicate logic 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,

Page 51: A Formal Descriptive Semantics of UML and Its Applications Hong Zhu Department of Computing and Electronics School of Technology.

References1. Hong Zhu, Ian Bayley, Lijun Shan and Richard Amphlett, Tool

Support for Design Patterns in Model-Driven Development, submitted to ICSE 2009.

2. Lijun Shan and Hong Zhu, A Formal Descriptive Semantics of UML, Proc. of ICFEM’08, 27-31 October 2008 Kitakyushu-City, Japan. (In press)

3. Ian Bayley and Hong Zhu, On the Composition of Design Patterns, Proc. of QSIC’08, IEEE CS Press, 12-13 August, 2008, Oxford, UK.  

4. Ian Bayley and Hong Zhu, Specifying Behavioural Features of Design Patterns in First Order Logic, Proc. of COMPSAC’08, (Note: A full length version: Technical report TR-08-01, Department of Computing, Oxford Brookes Univ., Oxford, UK).

5. Ian Bayley and Hong Zhu, Formalising Design Patterns in Predicate Logic, Proc. of SEFM’07, London, UK, Sept. 2007.