UML Model architecture Object Constraint Language Lectures P9-P11 T120B029 2012 pavasario sem.

Slides:



Advertisements
Similar presentations
Formal Methods of Systems Specification Logical Specification of Hard- and Software Dr. Armin Wolf Fraunhofer Institut für Rechnerarchitektur.
Advertisements

Language Specification using Metamodelling Joachim Fischer Humboldt University Berlin LAB Workshop Geneva
Profiles Construction Eclipse ECESIS Project Construction of Complex UML Profiles UPM ETSI Telecomunicación Ciudad Universitaria s/n Madrid 28040,
The role of OCL in the Model Driven Architecture Jos Warmer Klasse Objecten
Comparison of Several Meta-modeling Tools 2 Yi Lu Computer Science Department McGill University
Semantics Static semantics Dynamic semantics attribute grammars
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
8. Introduction to Denotational Semantics. © O. Nierstrasz PS — Denotational Semantics 8.2 Roadmap Overview:  Syntax and Semantics  Semantics of Expressions.
OCL2 April A presentation of OCL 2 Object Constraint Language Christian Hein, Fraunhofer FOKUS April 2006.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
CS 330 Programming Languages 09 / 18 / 2007 Instructor: Michael Eckmann.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
A Formal Foundation Supporting MDD --- ZOOM Approach Hongming Liu Lizhang Qin 11/08/2003.
PSUCS322 HM 1 Languages and Compiler Design II Formal Semantics Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring.
Semantics with Applications Mooly Sagiv Schrirber html:// Textbooks:Winskel The.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
Object Oriented Databases - Overview
® Eurostep.ESUKPC v0.1©Copyright Eurostep Limited An Introduction to ISO STEP Part 25 David Price.
Visualization By: Simon Luangsisombath. Canonical Visualization  Architectural modeling notations are ways to organize information  Canonical notation.
SEG4110 – Advanced Software Engineering and Reengineering TOPIC E Object Constraint Language (OCL)
Ranga Rodrigo. Class is central to object oriented programming.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Workshop on Integrated Application of Formal Languages, Geneva J.Fischer Mappings, Use of MOF for Language Families Joachim Fischer Workshop on.
1 The Object Constraint Language Jos Warmer and Anneke Kleppe. OCL: The Constraint Language of the UML, Journal of Object-Oriented Programming, 2(2):10-13,
A presentation of OCL 2 Object Constraint Language Fraunhofer FOKUS.
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
Agenda 1. Introduction 2. Overview of SU-MoVal 3. OCL-based Model Validation 4. QVT-based Transformations 5. Demo of SU-MoVal 6. Conclusion and Future.
Building Tools by Model Transformations in Eclipse Oskars Vilitis, Audris Kalnins, Edgars Celms, Elina Kalnina, Agris Sostaks, Janis Barzdins Institute.
111 Writing Protocols in OCL CS 4311 Jos B. Warmer and Anneke G. Kleppe, OCL: The Constraint Language of the UML, JOOP, May Jos B. Warmer and Anneke.
PART I: overview material
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
CS 363 Comparative Programming Languages Semantics.
1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.
These courseware materials are to be used in conjunction with Software Engineering: A Practitioner’s Approach, 6/e and are provided with permission by.
Sheet 1 DocEng’03, Grenoble, November 2003 Model Driven Architecture based XML Processing Ivan Kurtev, Klaas van den Berg University of Twente, the Netherlands.
IM NTU Software Development Methods, Fall2006 Software Development Methods, Fall 2006 OCL 2006/12/ Object Constraint Language (OCL) Yih-Kuen Tsay.
Institute for Software Integrated Systems Vanderbilt University Object Constraint Language Himanshu Neema Krishnakumar Balasubramanian Jeff Parsons November.
Chapter 3 Part II Describing Syntax and Semantics.
Programming Languages and Design Lecture 3 Semantic Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
Object Constraint Language
1 Kyung Hee University Constraints Spring Kyung Hee University Graphical Notations  Graphical notations are well suited for displaying structural.
1 / 48 Formal a Language Theory and Describing Semantics Principles of Programming Languages 4.
Software Engineering 2 -Prakash Shrestha.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
UML Profile BY RAEF MOUSHEIMISH. Background Model is a description of system or part of a system using well- defined language. Model is a description.
CSC3315 (Spring 2009)1 CSC 3315 Languages & Compilers Hamid Harroud School of Science and Engineering, Akhawayn University
C HAPTER 3 Describing Syntax and Semantics. D YNAMIC S EMANTICS Describing syntax is relatively simple There is no single widely acceptable notation or.
Interpreting the Object Constraint Presented by: Ed Kausmeyer.
Object Design More Design Patterns Object Constraint Language Object Design Specifying Interfaces Review Exam 2 CEN 4010 Class 18 – 11/03.
A UML-Based Pattern Specification Technique Presented by Chin-Yi Tsai IEEE TRANSACTION ON SOFTWARE ENGINEERING, VOL. 30, NO. 3, MARCH 2004 Robert B. France,
Notices Assn 2 is due tomorrow, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including today’s lecture: Big Topics are.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Comparison of ZOOM with other Formal Methodologies Hsiu-Chien Jing SE690 Initial Presentation School of CTI, DePaul University Supervised by Dr. Jia October,
Defects of UML Yang Yichuan. For the Presentation Something you know Instead of lots of new stuff. Cases Instead of Concepts. Methodology instead of the.
Crosscutting Capabilities for Java and AspectJ through DJ
Extending UML.
The Object Constraint Language
UML Model architecture Object Constraint Language
UML: Unified Modeling Language
A Specification Language
Midterm Review CSU 670 Spring 2004.
The Object Constraint Language
Chapter 3 Describing Syntax and Semantics.
Formal Methods in Software Engineering 1
Software Architecture & Design
Presentation transcript:

UML Model architecture Object Constraint Language Lectures P9-P11 T120B pavasario sem.

2 UML language architecture UML metamodel defines meaning of UML models Defined in a metacircular manner, using a subset of UML to specify itself UML metamodel bootstraps itself. Similar: –compiler compiles itself –grammar defines itself –class dictionary defines itself

3 4 layer metamodel architecture UML metamodel one of the layers Why four layers? Proven architecture for complex models Validates core constructs by using them to define themselves

4 Four layer architecture meta-metamodel –language for specifying metamodels metamodel –language for specifying models model –language for specifying objects in some domain user objects

5 Four levels User Objects in running system –check run-time constraints Model of System under design –specify run-time constraints Meta-model –specify constraints on use of constructs in model Meta-metamodel –data interchange between modeling tools

6 Three layers of Demeter user object O P CLCL CBCB model O L metamodel O B TPTP TLTL TBTB classes objects text sentence class dictionary a class dictionary for class dictionaries your behavior and aspect files Demeter behavior and aspect files instance of defines classes B: metamodel L: model P: user objects

7 Icon C B O B C L T B O L T L O P T P Use as reminder for Demeter Tiling. Demeter Tiling

8 UML OCL Object Constraint Language –allows you to define side effect-free constraints for UML and other models (for example adaptive programs) –used in UML to defined well-formedness rules of the UML meta model (invariants for meta model classes)

9 Why OCL It is a formal mathematical language Tend to be hard to use by average modelers OCL is intended for average modelers Developed as business modeling language within IBM insurance division (has roots in Syntropy method) OCL is a pure expression language (side effect free)

10 Companies behind OCL Rational Software, Microsoft, Hewlett- Packard, Oracle, Sterling Software, MCI Systemhouse, Unisys, ICON Computing, IntelliCorp, i-Logix, IBM, ObjecTime, Platinum Technology, Ptech, Taskon, Reich Technologies, Softeam

11 Where to use OCL? Specify invariants for classes and types Specify pre- and post-conditions for methods As a navigation language

12 OCL properties LL(1) language –finally back to the Pascal days! –Grammar provided uses EBNF syntax Parser generated by JavaCC ISO-14977

13 What is ISO ? As examples the following syntax- rules illustrate the facilities for expressing repetition: aa = "A"; bb=3*aa, "B"; Terminal-strings defined by these rules are as follows: aa: A bb: AAAB

14 What is OCL? Predicate calculus for objects Traditional predicate calculus: –individuals –variables, predicate and function symbols –terms (for all, Boolean connectives) –axioms and the theories they define (group theory, number theory, etc.) In OCL: individuals -> objects

15 Structured individuals some “structural” constraints imposed by UML class diagram; further constraints can be imposed by OCL expressions annotated UML class diagram defines textual representation

16 Connection to model Self. Each OCL expression is written in the context of an instance of a specific type. Company self.numberOfEmployees c : Company c.numberOfEmployees

17 Connection to model Invariants of a type. An OCL expression stereotyped with >. An invariant must be true for all instances of the type at any time. Person self.age >= 0

18 Example: UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className Note: we use a thick arrow to denote inheritance. UML uses an open arrow.

19 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className number of concrete classes

20 Example Number of concrete classes: –ClassGraph self.entries-> select(c:Entry|c. oclIsTypeOf(ClassDef))-> collect(body)-> select (b:Body|b. oclIsTypeOf(Concrete)) ->size -> collection op select:subset collect:new set

21 Pre- and post-conditions constraints stereotyped with > and > for an operation or method. Example: Type::op(param1 : Type1 …): ReturnType pre: param1 … Post: result = …

22 Pre- and post-conditions Example: Post condition for insert operation: person.allInstances -> forAll(p1, p2 | p1 <> p2 implies p1.id <> p2.id)

23 Basic values and types Boolean true, false –and or xor not implies if-then-else Integer subtype of Real –* + - / abs Real 3.14 –* + - / floor String ‘ To be or not to be ’ –toUpper concat

24 Basic values and types Collection –Setsubtype of Collection –Sequencesubtype of Collection –Bagsubtype of Collection if element types conform to each other

25 Types from the UML Model Each OCL expression lives in the context of a UML model, a number of types/classes and their features and associations and their generalizations. All types/classes from the UML model are types in OCL.

26 Type Conformance OCL is typed Type conformance rules for types in the class diagram are simple: –each type conforms to its supertype –type conformance is transitive

27 Objects and properties The value of a property on an object that is defined in a class diagram is specified by a dot followed by the property name. Atype self.property

28 Properties an attribute an association end an operation with isQuery true a method with isQuery true

29 Properties an attribute Person self.age >= 0 self.employer->size an association end Company self.manager --type Person self.employee--type Set(Person)

30 Properties an operation with isQuery true Person self.income(aDate) Company self.stockPrice ()

31 Missing role names Whenever a role name is missing at one of the ends of an association, the name of the type at the association end, starting with a lowercase character is used as role name. If this results in an ambiguity, the role name is mandatory

32 Navigation over associations Company self.manager object of type Person or Set(Person) –used as Set(Person) self.manager->size -- result 1 –used as Person self.manager.age

33 OclType and OclAny All types in a UML model, or predefined within UML have a type. This type is an instance of the OCL type called OclType. OclType: meta type of all types. OclAny supertype of all types. OclType : Class = OclAny : Object (analogy to Java) Features of OclType: good for meta programming.

34 Predefined OCL types OclType: type: instance of OclType –type.name : String –type.attributes:Set(String) –type.associationEnds:Set(String ) –type.operations:Set(String) –type.supertypes:Set(OclType) –type.allSupertypes:Set(OclType) –type.allInstances:Set(type)

35 Similarity: java.lang.Class instances of class Class represent classes and interfaces in a way that can be read (but not modified) by a running Java program public final class Class{ public String getName(); public Class getSuperClass(); public Class[] getInterfaces();...

36 Predefined OCL types OclAny: supertype of all types in the model. object: instance of OclAny –object=(object2:OclAny) –object<>(object2:OclAny):Boolea n –object.oclType:OclType –object.oclIsKindOf(type:OclType ): Boolean

37 Similarity: java.lang.Object All objects, including arrays, implement the methods of this class public class Object { public final Class getClass(); public boolean equals(Object obj);...

38 Predefined features on all objects (OclAny) Type of an object oclType : OclType Feature oclType results in type of an object Direct type oclIsTypeOf(t:OclType):Boolean Direct or super type oclIsKindOf(t:OclType):Boolean

39 Examples Person self.oclType results in Person Person self.oclIsTypeOf(Person)--true self.oclIsTypeOf(Company)--false

40 Predefined features on types Two kinds of properties –on instances of classes –on types/classes themselves Most important predefined feature on each type: allInstances Person.allInstances -> forAll(p1, p2 | p1 <> p2 implies p1.id <> p2.id)

41 Collections Navigation will most often result in a collection. Collection predefined Large number of predefined operations Collection(X) : Set(X)|Sequence(X)|Bag(X). Specifiable by a literal

42 Collection type conformance Collection(X) is a subtype of OclAny. Rules (only 3 collection specific) –T1 conforms to T2 if T1=T2. –T1 conforms to T2 when T1 is a subtype of T2. –Collection(T1) conforms to Collection(T2) if T1 conforms to T2 –conformance is transitive

43 Previous value in post- conditions Pre- and post-conditions on operations and methods –the value of a property at the start of the operation or method –the value of a property upon completion of the operation or method Person::birthdayHappens() post: age = + 1

44 Collection Operations Select and reject operations –collection->select(boolean- expr) Company self.employee->select(age > 50) –collection->select (v|boolean-expr-with-v) Company self.employee->select (p|p.age > 50)

45 Collection Operations Select and reject operations –collection->select (v:Type|boolean-expr-with-v) Company self.employee->select (p:Person|p.age > 50)

46 Select syntax Define a subset –collection->select (v:Type|boolean-expr-with-v) –collection->select (v|boolean-expr-with-v) –collection->select (boolean-expr) refer to parts refer to entire object type redundancy

47 Reject syntax Define a subset –collection->reject (v:Type|boolean-expr-with-v) –collection->reject (v|boolean-expr-with-v) –collection->reject (boolean-expr) Instead negate expression

48 Collect syntax –collection->collect (v:Type|expr-with-v) –collection->collect (v|expr-with-v) –collection->collect (expr) Creates a bag self.empl->collect(bdate)->asSet Build new colletion by applying expression to elements of old collection

49 Shorthand for Collect Because navigation through many objects is very common, there is a shorthand notation for collect that makes OCL expressions more readable. Both are correct: –self.employee -> collect(birthdate.year) –self.employee.birthdate.year Violations of Law of Demeter!

50 ForAll operation All elements satisfy Boolean expression –collection->forAll (v:Type|boolean-expr-with-v) –collection->forAll (v|boolean-expr-with-v) –collection->forAll (boolean-expr)

51 Exists operation At least one element satisfies Boolean expression –collection->exists (v:Type|boolean-expr-with-v) –collection->exists (v|boolean-expr-with-v) –collection->exists (boolean-expr)

52 Predefined OCL types Integer, Real, String, Boolean OclExpression, OclType, OclAny OclType –all types defined in a model have type OclType –allows access to the meta-level of the model

53 Predefined OCL types OclType: type: instance of OclType –type.name : String –type.attributes:Set(String) –type.associationEnds:Set(String ) –type.operations:Set(String) –type.supertypes:Set(OclType) –type.allSupertypes:Set(OclType) –type.allInstances:Set(type)

54 Predefined OCL types OclAny: supertype of all types in the model. object: instance of OclAny –object=(object2:OclAny) –object<>(object2:OclAny):Boolea n –object.oclType:OclType –object.oclIsKindOf(type:OclType ): Boolean

55 Applications Number of class definitions: – ClassGraph self.entries->size wrong – ClassGraph self.entries-> select(c:Entry|c. oclIsTypeOf(ClassDef))->size ClassGraph EParse BParse ClassDef Entry0..* entries

56 Applications Number of class definitions: What about using strategies to define collections? – ClassGraph self.{to ClassDef} ->size ClassGraph EParse BParse ClassDef Entry0..* entries

57 Improve OCL: make adaptive OCL stresses the importance of collections Collections are best specified adaptively A strategy SS = (S, B, s, t) with source s and target set t and name map N for class graph G defines a collection of objects contained in a N(s)-object. The collection type CT is the union of N(t 1 ) for t 1 in t. 

58 Improve OCL The collection consists of CT-objects reached during the traversal of the N(s) object following strategy SS.

59 Properties In OCL –an attribute –an association end –an operation with isQuery true –a method with isQuery true Add for adaptive OCL –a strategy { … } with a single source

60 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className ClassGraph -- concrete classes self.{to Concrete}->size

61 Applications Number of concrete classes: –ClassGraph self.entries-> select(c:Entry|c. oclIsTypeOf(ClassDef))-> collect(body)-> select (b:Body|b. oclIsTypeOf(Concrete)) ->size

62 ClassGraph self.entries-> select(c:Entry|c. oclIsTypeOf(ClassDef))-> collect(body)-> select (b:Body|b. oclIsTypeOf(Concrete)) ->size -- count concrete classes ClassGraph -- count concrete classes self.{to Concrete}->size Which one is easier to write?

63 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className

64 Applications Terminal buffer rule ClassGraph self.{to ClassDef} ->forAll(r|r.termBProp()) ClassDef Boolean termBProp(){ partCNs=self.{via Part to ClassName}; result=if (partCNs->size)>1 then (partCNs->intersection(predefCNs)) -> isEmpty else true endif}

65 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className

66 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className

67 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className

68 Applications Class graph is flat ClassGraph self.{to Abstract}-> forAll(a|a.parts->size=0)

69 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className

70 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className

71 Applications Abstract superclass rule ClassGraph superCls = self.{through->*,super,* to ClassName}; self.{to ClassDef}-> forAll(c| if (superCls->includes(c.className)) then c.{to Abstract}->size=1 else true endif)

72 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className

73 UML class diagram ClassGraph ClassGraph EParse BParse ClassDef Entry0..* entries Body Part ClassName 0..* parts Concrete Abstract super className

74 Conclusions OCL is a suitable language for expressing object properties, class invariants and method pre- and post-conditions. (needs capability to define functions and auxiliary variables). OCL is NOT a good language for navigation but can be made into one by adding strategies.

75 Further information contains latest information about UML, specifically OCL.