Institute for Software Integrated Systems Vanderbilt University Object Constraint Language Himanshu Neema Krishnakumar Balasubramanian Jeff Parsons November.

Slides:



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

Design by Contract.
The role of OCL in the Model Driven Architecture Jos Warmer Klasse Objecten
Semantics Static semantics Dynamic semantics attribute grammars
Rigorous Software Development CSCI-GA Instructor: Thomas Wies Spring 2012 Lecture 11.
OCL2 April A presentation of OCL 2 Object Constraint Language Christian Hein, Fraunhofer FOKUS April 2006.
Page 1 Automatic Evaluation of Modelling Rules and Design Guidelines, July 2006 Automatic Evaluation of Modelling Rules and Design Guidelines Tibor Farkas,
CS 340 UML Class Diagrams. A model is an abstraction of a system, specifying the modeled system from a certain viewpoint and at a certain level of abstraction.
ISBN Chapter 3 Describing Syntax and Semantics.
CS 355 – Programming Languages
Feb 2003 R McFadyen1 Contracts (Ch 13) Used to help understand requirements more completely based on assertions; assertions are applicable to any.
Formal Methods of Systems Specification Logical Specification of Hard- and Software Prof. Dr. Holger Schlingloff Institut für Informatik der.
Specifying Agent Interaction Protocols with AUML and OCL COSC 6341 Project Presentation Alexei Lapouchnian November 29, 2000.
Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Katz Formal Specifications Larch 1 Algebraic Specification and Larch Formal Specifications of Complex Systems Shmuel Katz The Technion.
1 Specifying Object Interfaces. 2 Major tasks in this stage: --are there any missing attributes or operations? --how can we reduce coupling, make interface.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 18 Program Correctness To treat programming.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Describing Syntax and Semantics
Abstract data types What does ‘ abstract ’ mean? From Latin: to ‘ pull out ’— the essentials –To defer or hide the details –Abstraction emphasizes essentials.
Specifications Liskov Chapter 9 SWE 619 Last Updated Fall 2008.
SEG4110 – Advanced Software Engineering and Reengineering TOPIC E Object Constraint Language (OCL)
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
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,
An Object-Oriented Approach to Programming Logic and Design
A presentation of OCL 2 Object Constraint Language Fraunhofer FOKUS.
Chapter 9 Integrity. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.9-2 Topics in this Chapter Predicates and Propositions Internal vs.
1 COSC 4406 Software Engineering COSC 4406 Software Engineering Haibin Zhu, Ph.D. Dept. of Computer Science and mathematics, Nipissing University, 100.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
What is MOF? The Meta Object Facility (MOF) specification provides a set of CORBA interfaces that can be used to define and manipulate a set of interoperable.
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.
Approaching a Problem Where do we start? How do we proceed?
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic 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.
Week III  Recap from Last Week Review Classes Review Domain Model for EU-Bid & EU-Lease Aggregation Example (Reservation) Attribute Properties.
Object Oriented Software Development
IM NTU Software Development Methods, Fall2006 Software Development Methods, Fall 2006 OCL 2006/12/ Object Constraint Language (OCL) Yih-Kuen Tsay.
1 Kyung Hee University Constraints Spring Kyung Hee University Graphical Notations  Graphical notations are well suited for displaying structural.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
Object-Oriented Programming © 2013 Goodrich, Tamassia, Goldwasser1Object-Oriented Programming.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Chapter 16: UML Class Diagrams
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
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.
Class Diagrams. Terms and Concepts A class diagram is a diagram that shows a set of classes, interfaces, and collaborations and their relationships.
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.
CSCE 240 – Intro to Software Engineering Lecture 3.
SysML and Modelica Integration Working Group Meeting 3/11/09 Peter Fritzson Wladimir Schamai.
Jan Pettersen Nytun, UIA, page 1. Jan Pettersen Nytun, UIA, page 2 HISTORY COLLECTION TYPES AND QUERING IN OCL FORMAL LANGUAGE - STATEMENT EXAMPLES CONSTRAINTS.
UNIT-IV Designing Classes – Access Layer ‐ Object Storage ‐ Object Interoperability.
Learning to Program D is for Digital.
Used to help understand requirements more completely
Extending UML.
SysML v2 Formalism: Requirements & Benefits
Specifications Liskov Chapter 9
Modeling the OCL Standard Library
Business Process Measures
The Object Constraint Language
Chapter 4 Advanced Class Modeling
Programming Languages 2nd edition Tucker and Noonan
A Specification Language
Defining Classes and Methods
The Object Constraint Language
Object Constraint Language (OCL)
Formal Methods in Software Engineering 1
Programming Languages 2nd edition Tucker and Noonan
Presentation transcript:

Institute for Software Integrated Systems Vanderbilt University Object Constraint Language Himanshu Neema Krishnakumar Balasubramanian Jeff Parsons November 4, 2003

Why OCL? ADVANTAGES DISADVANTAGES Graphical Languages Easy to use Not rigorous Easy to read Expressing rule exceptions difficult Natural Languages Most familiar Ambiguous Formal Languages Powerful Require mathematics Unambiguous Not for everyone OCL fills a useful niche -- Unambiguous, but reasonably easy to use Intended for systems and business programmers Can also supplement graphical languages (GME)

OCL Ancestry Ernst Zermelo introduces set theory in 1908 Given present form by Adolph Fraenkel in 1922 Z (“zed”) based on set theory and predicate logic Syntropy adopted Z ideas, is direct ancestor of OCL OCL developed at IBM as a business modeling language OMG Request for Proposal (RFP) in 1996, submitted in 1997

OCL Overview - Properties  Originally intended for use within UML  Later used in other OMG specs  Used with graphical languages (GME)  Pure expression language  Not a programming language  No actions  No side effects  Typed language  Evaluation of expressions is “instantaneous”

OCL Overview - Uses  To specify invariants  type and class invariants in class models  invariants for UML metamodel itself  To specify constraints on “operations”  pre-conditions  post-conditions  let-expressions  definition constraints  To specify guards in state transitions  As a navigation language (Associations)

OCL Basic Types

GME Model Elements

Institute for Software Integrated Systems Vanderbilt University Himanshu’s part Constraints are key to success of any model. Just think how an instance of the model of society would behave when it doesn’t impose any constraint.. Imagine the possibilities -Himanshu Neema. The more constraints one imposes, the more one frees one's self. And the arbitrariness of the constraint serves only to obtain precision of execution. -Igor Stravinsky With OCL constraints you don’t have to deal with ambiguities like when somebody wrote a comment the formula of water is H2O, some highly intelligent user interpreted the formula to be H-I-J-K-L-M-N-O -Unknown Don’t constrain yourself not to smoke, it could even help you loose weight – one lung at a time - Unknown Let’s talk about interesting parts of the OCL…

Expression Context and Self package main::components context BondGraph inv: self.numGraphElements > 0 endpackage Alternative to ‘self’: context bg: BondGraph inv EnoughElementsConstraint: bg.numGraphElements > 0 Every OCL expression must have a context – basically the UML type to which the OCL constraint has to be applied Self refers to a contextual instance of the UML type in context Package context: Packages are used to organize UML types based on their purpose. Can be omitted when clear; Usually not used unless the model is big; if present, OCL constraints will be applied to UML types only in this package. context is UML type BondGraph Refers to an instance of BondGraph

Invariants, pre- and post- conditions context BondGraph::totalFlow(numElements: Integer) : Integer pre checkQty: numElements > 10 post checkResult: result > to access prev. value of a param at post-condition time Invariants on a UML type are the constraints which must evaluate to ‘true’ for every instance of this type. Pre-condition is a constraint associated with a behavioral feature of a UML type. When present, the pre-condition must evaluate to ‘true’ whenever a method can be invoked. Typically used to check if the parameters are legal. Post-condition is opposite of Pre-condition in the sense that it is checked after a method invoked has been executed. Typically used to check if the result being returned is legal. Could be recursive, i.e. can use itself, e.g. result = result + 1

Let Expressions and Definition Constraints context Person inv: let income:Integer = self.job.salary->sum() in if isUnemployed then self.income < 100 else self.income >= 100 endif context Person def: let income:Integer = self.job.salary->sum() To define an attribute or operation that can be used in constraints later just by its name Attributes, variables, and constraints declared using ‘let’ expressions has a scope of the current constraint that is being defined. Attributes, variables, and constraints defined using ‘def’ are reusable. They can be used in the same context as where any other property of a UML type can be used.

Other important specs Type Conformance rules, e.g. 1+false is invalid Casting: using oclAsType. If B inherits from A, then object pointing to B can be casted to A Precedence rules, e.g ‘*’  ‘/’ Infix operators, e.g if A has operator defined ‘+’, we can use a1+a2 [~ a1.+(b)] Undefined values Identity and Equality with ‘=‘ and ‘==‘ Comments: using ‘--’, e.g. “-- this is a comment” Enumeration stereotypes

Properties and Navigation.. context Person inv: let income:Integer = self.job.salary->sum() in if isUnemployed then self.income < 100 else self.income >= 100 endif context Person def: let income:Integer = self.job.salary->sum() Navigating association using opposite end’s rolename property like – object.rolename Returned type depends on the cardinality of association, if 0..1 or 1 then returned type is same as the associated type, else if more than 1 is possible then the returned type would be a set, e.g. context Company inv: self.manager.isUnemployed = false [example of associated type inv: self.employee->noyEmpty() [example of set] Note: a single object returned can also be used as a Set. If rolename is absent, name of the opposite association end type starting with a lowercase can be used. In case of ambiguity rolename must exist. If rolenames are ambiguous, they cannot be used in OCL. If cardinality is [0..1], this expression comes very handy context Person inv: self.wife->notEmpty() Navigation to association classes (in GME, connections): No rolename thus class name is used starting with a lowercase letter context Person inv: self.job Person Bool:isUnemployed Integer: age Company Job employee manager wife

Properties and Navigation In case of ambiguity, qualifiers need to be used, e.g in above figure in context of Person – self.employeeRanking[bosses]->sum() has to be used for employeeRankings belonging to collection of bosses. Navigation to association class, in case of recursion, the expression needs to be qualified. For navigating from an association class to associated types, use rolenames, e.g. context job inv: self.employee.age > 21 Navigation through qualified associations – uses one or more qualifier attributes to select the objects at the other end of the association Navigation to a specific type with full qualified path using package names, e.g. main::roster::Person type As described earlier, for accessing overridden properties of supertypes, we can use the casting e.g. if B inherits from A and overrides A’s property ‘prop1’, then context B inv: self.oclAsType(A).prop1 -- accesses property ‘prop1’ of supertype A self.prop1 -- accesses property ‘prop1’ of B Note: Again, qualifier is needed in case of ambiguity

Collections: Set, Bag, and Sequence  Collection is an abstract type – powerful means  Set, Bag, and Sequence derive from Collection  Set {1, 2, 5, 3} – no repetitions, order not necessary  Bag {1, 2, 3, 3, 2} – repetitions allowed, order not necessary  Sequence {1, 2, 2, 3, 5} – repetitions allowed, but order is necessary  Type conformation rules  Collection operations: Select, Reject, Collect  e.g. collection->collection_operation(v: Type| expr-with-v)  expr-with-v must be a boolean expression for Select and Collect  ForAll, Exists  Iterate Operation  Collection->iterate(elem:Type; acc:Type = | expr-with-elem-and- acc)  e.g. collection->iterate (x:T1; acc:T2 = Set{}| acc->including (x.getName()))

MCL – GME’s Meta Constraint Language - Issues Extension of OCL to GME specific types, all constraints e.g. collections, definitions, should also work with GME types MCL maintenance with upgrades in OCL, e.g. still not 100% compliant with OCL 2.0 Performance of MCL Parser and Constraint Evaluator – critical. Different heuristics can be used depending upon size & structure of the model and the type of constraint in question Error reporting – Detailed contents, User-friendly dialogs, Evaluation progress monitor, User interaction during evaluation When OCL or MetaGME paradigm is updated older constraints should still be compatible. Abort operation when any priority 1 constraint is violated Constraint preferences

MCL – GME’s Meta Constraint Language - Differences All predefined iterators are supported except ‘sortedBy’ MCL features have been added with extra security Extension of pre-defined OCL types with useful features e.g. meta-kind features, e.g. ocl::String::match(ocl::String) GME specific types have been introduced, e.g. gme::Object && gme::Folder, gme::Reference For gme::FCO kinds or for kinds whose ‘is Abstract’ property is ‘true’, it cannot be referred in constraints as the information is lost in the interpreted meta. Interface and Implementation inheritance cannot be distinguished as again the knowledge will be lost during interpretation GME specific features like – gme::FCO::connectedFCOs meta  gme  ocl  exception/undefined [3 namespaces] Read-only constraints defined in imported libraries

Navigation  Association Ends  Object.rolename  Return value: Set  OCL Example context Company inv: self.manager.isUnemployed = false inv: self.employee->notEmpty()  Missing Rolenames  name of type  Reflexive associations

Navigation  Assoc multiplicity  Return value: Both Set as well as Object  OCL Example context Company inv: self.manager->size() = 1 inv: self.manager.age > 40  Useful in navigation context Person inv: self.wife->notEmpty() implies self.wife.sex = Sex::female

Navigation  To Association Classes  Dot and name of class  OCL Example context Person inv: self.job  Reflexive associations  Distinguish direction  Qualifiers context Person inv: self.job[employers]

Navigation  From Association Classes  Dot and role-name  Return value  Always one Object  OCL Example context Job inv: self.employer.numberofEmployees >= 1 self.employee.age > 21

Navigation  Overridden Properties  OCL Example context Dependency inv: self.src <> self  Ambiguity  Normal Navigation  Association class Navigation context Dependency inv: self.oclAsType (Dependency).src inv: self.oclAsType (ModelElement).src

Predefined Properties oclIsTypeOf (t: OclType) : Boolean oclIsKindof (t: OclType) : Boolean oclInState (s: OclState) : Boolean oclIsNew(): Boolean oclAsType (t: OclType) : instance of OclType  OCL Example context Person inv: self.oclIsTypeOf(Person) – True inv: self.oclIsTypeOf(Company) -- False

Previous values in Post-Conditions  Expression can refer:  To value at start  To value upon completion  OCL Example context Person::birthdayHappens() post: age = + 1  More Examples  Difference between &

Collection Operations  Set  Bag  Sequence  Operations  select(), reject()  collect()  forall()  OCL Examples context Company inv: self.employee->reject(isMarried)->isEmpty() self.employee->collect(person| person.birthdate) self.employee->forAll (p: Person | p.forename = ‘Jack’)

Collection Operations  Iterate  Mother of All Operations collection->iterate (elem:Type; acc: Type = | expression-with-elem-and-acc)  i.e., collection->collect (x: T | x.property)  Is identical to collection->iterate (x: T; acc: T2 = Bag{} | acc->including (x.property))

GME & OCL  Only invariants can be written  Do s and Don’t s (Refer to manual)  Fav. Quote from Manual “As an expert GME user knows, …”  Detailed usage instructions

OCL 2.0  OCL 1.4  No metamodel  Integration problems with UML  OCL 2.0  Define MOF compliant metamodel  Define concepts and semantics  Act as an abstract syntax  (Re)Define OCL 1.4 as concrete syntax of the above syntax  Separation between metamodel and concrete syntax  Alternative concrete syntaxes (e.g. visual constraint diagrams)  Metamorphosis  Constraint language  Object query language  Behavioural constraints

Questions ?