Object Constraint Language 2

Similar documents
Software Engineering

Unified Modeling Language 2

Rubby Casallas Grupo de Construcción de Software Uniandes

What is OCL? OCL/Context

Appendix A OCL 2.0 Grammar

UNIT II. Syllabus. a. An Overview of the UML: Visualizing, Specifying, Constructing, Documenting


Chapter 8, Object Design: Object Constraint Language

OCL and Concept Model

Composite Structures

Architectural Models and Styles Component-Based Software Engineering ECE493-Topic 5 Winter 2007 Lecture 12 The Object Constraint Language (Part A)

course: Database Systems (NDBI025) SS2017/18

Specification with OCL

Specification-based Testing of Embedded Systems H. Schlingloff, SEFM 2008

Specification-based Testing of Embedded Systems H. Schlingloff, SEFM 2008

Formal Methods in Software Engineering 1

Index. business modeling syntax 181 business process modeling 57 business rule 40

SLIDES: Introductory Modeling Example Employing UML and OCL [UML: Unified Modeling Language, OCL:Object Constarint Language]

The Object Constraint Language (OCL)

OCL Object Constraint Language

The Object Contraint Language by Example

UML Class Diagrams 2. Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague

7 OCL Language Description

Generating Alternative Representations for OCL Integrity Constraints

Model-Driven Language Engineering. Franck Fleurey

Object Constraint Language Specification 7

Lecture 9. UML language architecture

ATL: Atlas Transformation Language. ATL User Manual

OCL 2.0 Specification Version 2.0

Formal Methods in Software Engineering 1

Design and Implementation of a UML/OCL Compiler

UNIT-II Introduction to UML

Recursion and iteration support in USE Validator with AnATLyzer

ATL Transformation Examples. The KM3 to Metric ATL transformation

Constraint-enabled Process Modeling. Conrad Bock U.S. National Institute of Standards and Technology November 20, 2007

Recursion and Iteration Support in USE Validator with AnATLyzer

Metamodeling. Janos Sztipanovits ISIS, Vanderbilt University

Hans Karlsen. MDriven The book. Doing effective Business by taking control of Information. Hans Karlsen, Stockholm, Sweden

Collections, Maps and Generics

CONSTRAINT SPECIFICATIONS USING PATTERNS IN OCL

Reusing OCL in a Programming Language

Chapter 9 Object Design: Specifying Interfaces

Report on the Aachen OCL Meeting

2. The object-oriented paradigm

OCL omissions and contradictions

Inheritance. Transitivity

Advanced JML Erik Poll Radboud University Nijmegen

Subclassing for ADTs Implementation

Java. Representing Data. Representing data. Primitive data types

Formal Foundations of Software Engineering

JML Class Specifications The Java Modeling Language (Part 2) A Java Class

CIS 120 Midterm II November 16, 2012 SOLUTIONS

Metamodeling with Metamodels. Using. UML/MOF including OCL

doc. RNDr. Tomáš Skopal, Ph.D. Mgr. Martin Nečaský, Ph.D. RNDr. Michal Kopecký, Ph.D.

The Java Modeling Language (Part 2)

The Liskov Substitution Principle

Computing the Relevant Instances that May Violate an OCL constraint

Software Design, Modelling and Analysis in UML

Software Design, Modelling and Analysis in UML

Relational Model. Course A7B36DBS: Database Systems. Lecture 02: Martin Svoboda Irena Holubová Tomáš Skopal

CIS 120 Midterm II November 16, Name (printed): Pennkey (login id):

Software Design, Modelling and Analysis in UML

Relational Model. Courses B0B36DBS, A4B33DS, A7B36DBS: Database Systems. Lecture 02: Martin Svoboda

Operators and Expressions

Data Structures and Algorithms. Chapter 1

COS 140: Foundations of Computer Science

In this lab, you will be given the implementation of the classes GeometricObject, Circle, and Rectangle, as shown in the following UML class diagram.

Agenda. More on the Unified Modeling Language. UML diagram types. Packages

Software Design, Modelling and Analysis in UML

Programming with Contracts. Juan Pablo Galeotti, Alessandra Gorla Saarland University, Germany

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

JML OCL. Java. iterate

QVT: Query, Views, Transformations

Type Hierarchy. Comp-303 : Programming Techniques Lecture 9. Alexandre Denault Computer Science McGill University Winter 2004

Chapter 9, Object Design: Specifying Interfaces

Student Performance Q&A:

Rigorous Software Development CSCI-GA

Conceptual Database Modeling

A Short Summary of Javali

CS171 Midterm Exam. October 29, Name:

COSC 304 Introduction to Database Systems SQL DDL. Dr. Ramon Lawrence University of British Columbia Okanagan

Comp Intermediate Programming EXAM #1 February 16, 2004 Rice University - Instructors: Cox & Nguyen

Object Constraint Language Specification

CONTENTS. PART 1 Structured Programming 1. 1 Getting started 3. 2 Basic programming elements 17

Operators. Java operators are classified into three categories:

Learning Recursion. Recursion [ Why is it important?] ~7 easy marks in Exam Paper. Step 1. Understand Code. Step 2. Understand Execution

Name: CS 159 Practice Final Fall 2015

Input Space Partitioning

GSN Metamodel. In the following subsections we describe the model elements. All references are to sections within the GSN Community Standard.

AP CS A Karel J Robot Review Sheet Chapters 5-6

CIS 771: Software Specifications. Lecture 14: Advanced OCL Expressions

Enforcing Modeling Guidelines in an ORDBMS-based UML-Repository

EXAMINATIONS 2011 Trimester 2, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS

used in the industry for software specifications. Once an application has been specified, Model Driven Architecture (MDA) techniques can be applied

Software Engineering: A Practitioner s s Approach, 6/e Roger Pressman. Chapter 28 Formal Methods

9. Object Design: Specifying Interfaces

Assertions! How to write correct programs and know it! Harlan Mills! Gunnar Gotshalks! 08-1

Name: CS 159 Practice Final Fall 2015

Object-Oriented Design Lecture 11 CS 3500 Spring 2010 (Pucella) Tuesday, Feb 16, 2010

FORM 2 (Please put your name and form # on the scantron!!!!)

Transcription:

Object Constraint Language 2 Martin Nečaský Dept. of Software Engineering Faculty of Mathematics and Physics Charles University in Prague

Type System predefined types in OCL standard library generic types OclAny, OclInvalid basic types similar to those in other known languages Boolean, Real, Integer, String collection types results of navigation through associations in class diagrams Collection Set, Bag, OrderedSet, Sequence user-defined types defined by a user in UML diagrams every instantiable model element in UML diagrams is automatically a type in OCL expressions

OclInvalid OclInvalid = {invalid} conforms to all other types i.e. invalid can be an instance of any type in OCL any property call applied on invalid results in invalid except for oclisundefined() and oclisinvalid()

OclAny behaves as a supertype for all OCL types a = b, a <> b : Boolean equals, not equals a.oclisnew() : Boolean true if a is created during performing an operation can only be used in the operation postcondition a.oclisundefined() : Boolean true if a is equal to invalid or equal to null a.oclisinvalid() : Boolean true if a is equal to invalid a.oclistypeof(t : Classifier) : Boolean true if a is of the type t but not a subtype of t a.ocliskindof(t : Classifier) : Boolean true if a is of the type t or a subtype of t a.ocltype() : Classifier evaluates to type of a

Boolean represents common true/false values a or b, a xor b : Boolean a and b : Boolean a implies b : Boolean not (a) : Boolean

Real mathematical concept of real a + b, a b, -a : Real a * b : Real a / b : Real a < b, a > b : Boolean a <= b, a >= b : Boolean a.abs() : Real a.floor(), a.round() : Integer a.min(b : Real) : Real a.max(b : Real) : Real

Integer mathematical concept of integer subclass of Real a + b, a b, -a : Integer a * b : Integer a / b : Real a.abs() : Integer a.div(b : Integer) : Integer a.mod(b : Integer) : Integer a.min(b : Integer) : Integer a.max(b : Integer) : Integer

String string is a sequence of characters in some suitable character set used to display information about the model a + b : String a.size() : Integer a.concat(b) : String a.substring(s, e: Integer) : String substring starting and ending at positions between 1 and a.size() a.tointeger() : Integer,... a.touppercase() : String a.tolowercase() : String...

Collections navigation via properties (association ends or attributes) results in a Collection Collection is an abstract type with four concrete sub-types: Set OrderedSet Bag Sequence

Navigation navigation via property p from a a.p a is self or a variable with an instance results to single instance (object or value) or an empty Set when the max multiplicity of p equals to 1 a Set when the max multiplicity of p is greater than 1 an OrderedSet when the max multiplicity of p is greater than 1 and p is modified by {ordered}

Navigation navigation via a chain of properties p1...pn from a results to Bag a.p1...pn

Collection Constants Set{1,2,5,88} Sequence{'apple', 'orange', 'pear'} Sequence{1..(6+4)}

Collection Iterator Operations different operations which iterate a collection and create a new collection from the existing one select and reject specify a selection from class Example_01 a collection Person +reviewer + name: String collect 0..2 + number: String + salary: Int 1..* +author forall + getcurrentwork(kindofwork) : Document + reviewdocument(document) : void +authoreddoc 0..* + increasesalary(int) : void Document + isreviewer() : Boolean exists closure + name: String +output 0..* + startdate: Date iterate + enddate: Date +project +/ teamsize: Int 1... and more +worker 1..* +project 0..* Proj ect + publishdocument(document) : void + getauthors() : Person[] +revieweddoc 0..* + serialnumber: Int + pages: Int + title: String + estimatedworkhours: Int + status: DocStatus

Collection Iterator Operations general syntax of iterator operations is col->op(expression) or col->op(v expression-with-v) or col->op(v: Type expression-with-v) sub-expressions of expression and expression-with-v implicitly start with the iteration variable when it is not present contextual instance is referred by self reserved word but self is not implicit context Person inv: project ->op(startdate > self.startdate) context Person inv: self.project ->op(p p.startdate > self.startdate)

Select and Reject Operations select specifies a subset of a collection containing all elements of the original collection for which a given expression evaluates to true collection->select(boolean-expression) for each element of the original collection, evaluate the expression and put the result into the new collection

Select and Reject Operations reject specifies a subset of a collection containing all elements of the original collection for which a given expression evaluates to false collection->reject(boolean-expression) ~ collection->select(not(boolean-expression))

Select class Example_01 and Reject Operations + name: String + number: String + salary: Int Person + getcurrentwork(kindofwork) : Document + reviewdocument(document) : void + increasesalary(int) : void + isreviewer() : Boolean +worker 1..* +project 0..* Proj ect + name: String + startdate: Date + enddate: Date +/ teamsize: Int + publishdocument(document) : void + getauthors() : Person[] 1..* +author +project 1 +reviewer 0..2 +authoreddoc 0..* +revieweddoc 0..* Document + serialnumber: Int + pages: Int + title: String + estimatedworkhours: Int + status: DocStatus +output 0..* context Person inv: self.authoreddoc ->reject(d self.project.output->includes(d)) ->size()=0

Collect Operation collect specifies a collection that is computed from other collection the new collection is not a sub-collection but contains elements computed/derived from the elements of the original collection collection->collect(expression) for each element of the original collection, evaluate the expression and put the result into the new collection

class Example_01 Collect Operation + name: String + number: String + salary: Int Person + getcurrentwork(kindofwork) : Document + reviewdocument(document) : void + increasesalary(int) : void + isreviewer() : Boolean +worker 1..* +project 0..* Proj ect + name: String + startdate: Date + enddate: Date +/ teamsize: Int + publishdocument(document) : void + getauthors() : Person[] 1..* +author +project 1 +reviewer 0..2 +authoreddoc 0..* +revieweddoc 0..* Document + serialnumber: Int + pages: Int + title: String + estimatedworkhours: Int + status: DocStatus +output 0..* context Person inv: self.authoreddoc->collect(d d.project)

Collect Operation collection->collect(propertyname) ~ collection.propertyname

ForAll Operation forall specifies a Boolean expression which must hold for all objects in a collection collection->forall(expression) extended variant with more than one iterators of the same collection iterator variables must be used in this case collection->forall(v1,v2 expression) ~ collection->forall(v1 collection->forall(v2 expression)

class Example_01 ForAll Operation + name: String + number: String + salary: Int Person + getcurrentwork(kindofwork) : Document + reviewdocument(document) : void + increasesalary(int) : void + isreviewer() : Boolean +worker 1..* +project 0..* Proj ect + name: String + startdate: Date + enddate: Date +/ teamsize: Int + publishdocument(document) : void + getauthors() : Person[] 1..* +author +project 1 +reviewer 0..2 +authoreddoc 0..* +revieweddoc 0..* Document + serialnumber: Int + pages: Int + title: String + estimatedworkhours: Int + status: DocStatus +output 0..* context Person inv: self.authoreddoc ->forall(d self.project.output->includes(d))

class Example_01 ForAll Operation + name: String + number: String + salary: Int Person + getcurrentwork(kindofwork) : Document + reviewdocument(document) : void + increasesalary(int) : void + isreviewer() : Boolean +worker 1..* +project 0..* Proj ect + name: String + startdate: Date + enddate: Date +/ teamsize: Int + publishdocument(document) : void + getauthors() : Person[] 1..* +author +project 1 +reviewer 0..2 +authoreddoc 0..* +revieweddoc 0..* Document + serialnumber: Int + pages: Int + title: String + estimatedworkhours: Int + status: DocStatus +output 0..* context Project inv: self.output->forall(d1,d2 d1<>d2 implies d1.serialnumber <> d2.serialnumber)

Exists Operation exists specifies a Boolean expression which must hold for at least one object in a collection collection->exists(expression) extended variant with more than one iterators is also possible

Closure Operation closure specifies a new collection created by a recursive application of an expression collection->closure(expression) allows for expressing a transitive closure the expressive power of OCL exceeds the power of relationally complete languages

Closure Operation class Example_01 0..* Person +boss 0..1 + name: String + number: String + salary: Int + getcurrentwork(kindofwork) : Document + reviewdocument(document) : void + increasesalary(int) : void + isreviewer() : Boolean context Person inv: self->asset()->closure(boss)->size() <= 3

Iterate Operation iterate is a general loop operation collection->iterate( element : Type1; result : Type2 = <initial-value-expression> <expression-with-element-and-result>) element is iterator result accumulates the resulting value it is also called accumulator for each element in collection, the expression is calculated using the previous value of result

Iterate Operation source->forall(v body ) = source->iterate( v; result : Boolean = true result and body(v)) source->exists(v body ) = source->iterate( v; result : Boolean = false result or body(v))

Other Operations on Collections collection->count(object) : Integer the number of occurences of the object in the collection collection->includes(object): Boolean true if the collection contains the object collection->isempty() : Boolean true if the collection is empty collection->size() : Integer the number of elements in the collection... and more

Other Operations on Collections difference to the iterator operations is that the default context variable is self, not the class Example_01 iteration variable context Person inv: self.authoreddoc-> excludesall(revieweddoc) context Person inv: self.authoreddoc-> excludesall(self.revieweddoc) + name: String + number: String + salary: Int Person + getcurrentwork(kindofwork) : Document + reviewdocument(document) : void + increasesalary(int) : void + isreviewer() : Boolean +worker 1..* +project 0..* Proj ect + name: String + startdate: Date + enddate: Date +/ teamsize: Int + publishdocument(document) : void + getauthors() : Person[] 1..* +author +project 1 +reviewer 0..2 +authoreddoc 0..* +revieweddoc 0..* Document + serialnumber: Int + pages: Int + title: String + estimatedworkhours: Int + status: DocStatus +output 0..*