Meta-Modeling with OCL & Kermeta

Meta-Modeling with OCL & Kermeta

Meta-modeling with OCL & KerMeta Prof. Jean-Marc Jézéquel (Univ. Rennes 1 & INRIA) Triskell Team @ IRISA Campus de Beaulieu F-35042 Rennes Cedex Tel : +33 299 847 192 Fax : +33 299 847 171 e-mail : [email protected] http://www.irisa.fr/prive/jezequel The World and the Model A Model is a simplified representation of an aspect of the World for a specific purpose – Consider modeling both the machine & its environment (M. Jackson) UML paved the way from OOP to Model Based SE Person CourseSession -personID : unsigned long -surname : CString -courseSessionID : unsigned long -givenName : CString -courseDate : unsigned long -middleInitial : char -teaches -courseID : unsigned long -streetAddress : CString Employee -courseLocation : CString RegForm ApplicantList PersonList Applicant Application ApplicationList -postCode : CString -jobType : CString -is taught by +CourseSession() -countryname : CString -roomNr : unsigned long 0..* +CourseSessionInfo() -eMailAddress : CString -department : CString +Person() -division : CString 1 1 -is in +PersonInfo() -jobTitle : CString -manager : unsigned long Specificity of Engineering: -headsDept : CString -headsDivision : CString findApplicant() -mobileNr : CString -birthDate : unsigned long +Employee() +GetCurrentAge() 0..* -is filled by Applicant +EmployeeInfo() findPerson() -companyName : CString CourseRegistration -experience : CString -is made by -makes -registrationDate : unsigned long -reference1 : CString -completionFlag : bool -reference2 : CString -confirmedDate : unsigned long Applicant() Model something not yet -reference3 : CString 1 0..* +CourseRegistration() +Applicant() +CourseRegistrationInfo() +ApplicantInfo() RegistrationForm +MakeApplication() MakeApplication() +registrationform() 1 -is made* by a-uses 1 -is taken by * existing(in order to build it) 0..* -takes Application() Test 1..* -made a -testScore : unsigned long addApplication() +Test() Application +TestInfo() PermittedStatusChange -productNr : unsigned long -allows change in -has a -fromStatus : char -certificationLevel : unsigned long 0..* -gives -toStatus : char addPerson() M -applicationDate : unsigned long +PermittedStatusChange() +Application() 0..* 1..* +StatusChangeInfo() 1 +ApplicationInfo() 0..* -applies to a 1 -is achieved (modeling 1 -is for a ExamSession Exam -uses -is used in -examSession : unsigned long -examID : unsigned long AppStatus -examlocation : CString -certificationLevel : unsigned long -statusCode : char -examDate : unsigned long +Exam() 1 -statusName : CString 0..* +ExamSession() +ExamInfo() +AppStatus() +ExamSessionInfo() space) Is represented by +AppStatusInfo() M0 (the world) © J.-M. Jézéquel, 2005 2 1 Assigning Meaning to Models If a UML model is no longer just – fancy pictures to decorate your room – a graphical syntax for C++/Java/C#/Eiffel... Then tools must be able to manipulate models Contains ModelElement +c onstrainedElement 0..1 1..* – Let’s make a model 0..* Constrains +container {ordered} 0..* Constraint of what a model is! +containedElement Namespace Feature +subtype – => meta-modeling Generaliz es 0..* GeneralizableElement BehavioralFeature Struc turalFeature +supertype » & meta-meta-modeling.. {ordered} 0..* » Use Meta-Object Package Classifier Operation Reference MofAttribute Facility (MOF) to avoid 0.. * +referent RefersTo infinite Meta-recursion Dat aType Class Association +referencedEnd 1 AssociationEnd © J.-M. Jézéquel, 2005 3 The 4 layers in practice © J.-M. Jézéquel, 2005 4 2 UML2 meta-model © J.-M. Jézéquel, 2005 (part.) 5 Zoom: comments © J.-M. Jézéquel, 2005 6 3 Generalizations © J.-M. Jézéquel, 2005 7 Static Semantics with OCL Complementing a meta-model with Well- Formedness Rules, aka Contracts e.g.; – ModelElement has a unique name in a Namespace – no cycle in a UML2 inheritance graph… Expressed with the OCL (Object Constraint Language) – The OCL is a language of typed expressions. – A constraint is a valid OCL expression of type Boolean. – A constraint is a restriction on one or more values of (part of) an object-oriented model or system. © J.-M. Jézéquel, 2005 8 4 OCL Can be used at both – M1 level (constraints on Models) »akaDesign-by-Contract (Meyer) – M2 level (constraints on Meta-Models) » aka Static semantics Let’s overview it with M1 level exemples © J.-M. Jézéquel, 2005 9 Class invariants Contraints can be added to models – notation: between { } Invariant = Boolean expression – True for all instances of a class in stable states... – Expressed with the OCL (Object Constraint Language) Bank_Account {balance>=lowest} » e.g. {balance >= lowest} » Can also navigate the associations balance: Money lowest: Money deposit (Money) withdraw(Money) © J.-M. Jézéquel, 2005 10 5 Precondition: Burden on the client Specification on what must be true for a client to be allowed to call a method – example: amount > 0 Notation in UML – {«precondition» OCL boolean expression} – Abbreviation: {pre: OCL boolean expression} © J.-M. Jézéquel, 2005 11 Postcondition: Burden on the implementor Specification on what must be true at completion of any successful call to a method –example: balance = balance @pre + amount Notation in UML – {«postcondition» OCL boolean expression} – Abbreviation: {post: OCL boolean expression} – Operator for previous value (idem old Eiffel): » OCL expression @pre © J.-M. Jézéquel, 2005 12 6 To be Abstract and Precise Bank_Account {balance>=lowest} balance: Money lowest: Money deposit (amount: Money) {pre: amount> 0} {post: balance = balance @pre + amount} withdraw(amount: Money) •In memory implementation •straightforward {pre: amount> 0 and montant<=balance-lowest} •list of transactions {post: balance = balance @pre - amount} •Data base implementation •etc. © J.-M. Jézéquel, 2005 13 Types in OCL The types in OCL are as follows: • Predefined types – Basic types - Integer, Real, String and Boolean – Collection types - Collection, Set, Bag, Sequence • Meta types – OclAny, OclExpression, OclType • User-defined model types – Enumeration and all classes, types and interfaces © J.-M. Jézéquel, 2005 14 7 Boolean Operation Notation Result type or a or b Boolean and a and b Boolean exclusive or a xor b Boolean negation not a Boolean equals a = b Boolean not equals a <> b Boolean implication a implies b Boolean if then else if a then b1 else b2 endif type of b © J.-M. Jézéquel, 2005 15 Real and Integer Operation Notation Result type equals a = b Boolean not equals a <> b Boolean less a < b Boolean more a > b Boolean less or equal a <= b Boolean more or equal a >= b Boolean plus a + b Integer or Real minus a - b Integer or Real multiply a * b Integer or Real divide a / b Real modulus a.mod(b) Integer integer division a.div(b) Integer absolute value a.abs Integer or Real maximum a.max(b) Integer or Real minimum a.min(b) Integer or Real round a.round Integer floor a.floor Integer © J.-M. Jézéquel, 2005 16 8 String Operation Expression Result type concatenation s.concat(string) String size s.size Integer to lower case s.toLower String to upper case s.toUpper String substring s.substring(int, int) String equals s1 = s2 Boolean not equals s1 <> s2 Boolean © J.-M. Jézéquel, 2005 17 Simple constraints Customer name: String title: String age: Integer isMale: Boolean title = if isMale then ‘Mr.’ else ‘Ms.’ endif age >= 18 and age < 66 name.size < 100 © J.-M. Jézéquel, 2005 18 9 Using Enumerations Customer gender: enum{male, female} name: String title: String dateOfBirth: Date gender = #male implies title = ‘Mr. ‘ © J.-M. Jézéquel, 2005 19 Non-local contracts: navigating associations Each association is a navigation path – The context of an OCL expression is the starting point – Role names are used to select which association is to be traversed (or target class name if only one) 1 owner ownership ownings * Person Car Context Car inv: self.owner.age >= 18 © J.-M. Jézéquel, 2005 20 10 Navigation of 0..* associations Through navigation, we no longer get a scalar but a collection of objects OCL defines 3 sub-types of collection – Set : when navigation of a 0..* association » Context Person inv: ownings return a Set[Car] » Each element is in the Set at most once – Bag : if more than one navigation step » An element can be present more than once in the Bag – Sequence : navigation of an association {ordered} » It is an ordered Bag Many predefined operations on type collection Syntax:: © J.-M. Jézéquel, 2005 Collection->operation 21 Constraint examples self.transaction -> forAll(t:Transaction | t.value > 100) Account 1 0..* Transaction SuperSaver Account self.balance > 0 © J.-M. Jézéquel, 2005 22 11 Navigating to collections Customer Account Transaction Customer self.account produces a set of Accounts Customer self.account.transaction produces a bag of transactions If we want to use this as a set we have to do the following self.account.transaction -> asSet © J.-M. Jézéquel, 2005 23 Collection hierarchy Collection Set Bag Sequence minus asSequence first symmetricDifference asSet last asSequence at(int) asBag append prepend asBag asSet © J.-M. Jézéquel, 2005 24 12 Basic operations on collections isEmpty – true if collection has no element Context Person inv: age<18 implies ownings->isEmpty notEmpty – true if collection has at least one element size – Number of elements in the collection count (elem) – Number of occurrences of element elem in the collection © J.-M. Jézéquel, 2005 25 Multiplicity constraints Vocabulary 110..* VocabElement 0..5 Hint Equivalent constraints expressed on the classes VocabElement self.hint -> size >= 0 and self.hint -> size <= 5 VocabElement

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    27 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us