Object Constraint Language in Together Dan Massey Y&L Consulting.

Slides:



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

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Air Force Institute of Technology Electrical and Computer Engineering
By Karen Richart. The Object Constraint Language (OCL)  Formal specification language that could be used for constraining the model elements that occur.
OCL2 April A presentation of OCL 2 Object Constraint Language Christian Hein, Fraunhofer FOKUS April 2006.
Getting started with ML ML is a functional programming language. ML is statically typed: The types of literals, values, expressions and functions in a.
Chapter 5 Types. 5-2 Topics in this Chapter Values vs. Variables Types vs. Representations Type Definition Operators Type Generators SQL Facilities.
1 Specifying Object Interfaces. 2 Major tasks in this stage: --are there any missing attributes or operations? --how can we reduce coupling, make interface.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 3 Control Statements.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
JavaScript, Third Edition
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements II.
® Eurostep.ESUKPC v0.1©Copyright Eurostep Limited An Introduction to ISO STEP Part 25 David Price.
SEG4110 – Advanced Software Engineering and Reengineering TOPIC E Object Constraint Language (OCL)
Chapter 5 new The Do…Loop Statement
Basic Concepts of Algebra
4. Python - Basic Operators
CIS162AD - C# Decision Statements 04_decisions.ppt.
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,
CIS Computer Programming Logic
Microsoft Visual Basic 2008: Reloaded Fourth Edition
2440: 211 Interactive Web Programming Expressions & Operators.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 4: The Selection Structure
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.
Flow of Control Part 1: Selection
Property of Jack Wilson, Cerritos College1 CIS Computer Programming Logic Programming Concepts Overview prepared by Jack Wilson Cerritos College.
Objects, Classes and Syntax Dr. Andrew Wallace PhD BEng(hons) EurIng
1 OCL The Role of OCL in UML. 2 רשימת הנושאים  מבוא  מרכיבי השפה  דוגמאות  מקורות.
Object Constraint Language in Together Dan Massey Y&L Consulting.
IM NTU Software Development Methods, Fall2006 Software Development Methods, Fall 2006 OCL 2006/12/ Object Constraint Language (OCL) Yih-Kuen Tsay.
1 Typing XQuery WANG Zhen (Selina) Something about the Internship Group Name: PROTHEO, Inria, France Research: Rewriting and strategies, Constraints,
CS-I MidTerm Review Hao Jiang Computer Science Department Boston College.
ANU COMP2110 Software Design in 2003 Lecture 10Slide 1 COMP2110 Software Design in 2004 Lecture 12 Documenting Detailed Design How to write down detailed.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Fluency with Information Technology Third Edition by Lawrence Snyder Chapter.
Chapter 16 UML Class Diagrams.
© 2006 Lawrenceville Press Slide 1 Chapter 6 The Post-Test Do…Loop Statement  Loop structure that executes a set of statements as long as a condition.
Chapter 14 JavaScript: Part II The Web Warrior Guide to Web Design Technologies.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
An Introduction to Programming with C++ Sixth Edition Chapter 5 The Selection Structure.
© 2010 Lawrenceville Press Slide 1 Chapter 5 The Do…Loop Statement  Loop structure that executes a set of statements as long as a condition is true. 
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Algebra 2 Properties of Real Numbers Lesson 1-2 Goals Goal To graph and order real numbers. To Identity properties of real numbers. Rubric Level 1 –
7 - Programming 7J, K, L, M, N, O – Handling Data.
VISUAL BASIC 6.0 Designed by Mrinal Kanti Nath.
UNIT-IV Designing Classes – Access Layer ‐ Object Storage ‐ Object Interoperability.
Presentation of a paper on “Model-based Software Testing”
The Object Constraint Language
Chapter 16 UML Class Diagrams.
Overview: Programming Concepts
The Selection Structure
The Object Constraint Language
Chapter 8: Control Structures
Chapter 5 The Do…Loop Statement
Specifying Object Interfaces
Chapter 8 JavaScript: Control Statements, Part 2
University of Kurdistan
The Object Constraint Language
Microsoft Visual Basic 2005: Reloaded Second Edition
SELECTIONS STATEMENTS
Boolean Expressions to Make Comparisons
Formal Methods in Software Engineering 1
Primitive Data Types and Operators
COMPUTING.
Introduction to Computer Science
Presentation transcript:

Object Constraint Language in Together Dan Massey Y&L Consulting

Picking up From Logicians Follows 3242 presentation to go in depth on OCL and using OCL in tools The preconference tutorial used the slides from session 3242 as the first third of the presentation.

OCL Topics OCL Basics The LiquidLemons Example OCL in Together Team Modeling Exercise

OCL Topics OCL Basics The LiquidLemons Example OCL in Together Team Modeling Exercise

OCL is Strongly typed declarative language Small set of built-in types, including collections User-defined types and operators

OCL Basic Types Booleantrue or false Integertheoretically unlimited natural numbers, subtype of Real Realmathematical Real, no specific implementation implied String‘sequence of characters’

Boolean Operations a : Booleanb : Boolean a and ba or ba xor b not aa = ba <> b a implies b implies constraint: if a is true then b must be true

Numeric Operators Comparison =equals<>not equals more =more or equal Math +addition-subtraction *multiplication/division

Every Type in OCL is an Object a : Integerb:Integer a.mod(b)a.div(b) a.abs()a.max(b) a.min(b)a.round() a.floor() Operators are just infix notation operations.

String Operations a : Stringb : String a = ba <> b a.concat(b)a.size() a.toLower()a.toUpper() a.subString(1, 3) Operations return new Strings.

OCL Conditional OCL provides one conditional construct: if then else endif No “elseif” or “switch”/“case”

OCL Operation Precedence Grouping() Path resolution:: Message notation. ->also ^ ^^ Unary- not Multiplication/Division* / Addition/Subtraction+ - Comparison = <> = Logicaland or xor Logical implicationimplies

User-Defined Types Classes, Interfaces, etc. defined in the model Users may overload infix and unary operators: Multiply Money by a Real Add two Distance values

OCL Collections Refreshing our memories, we have: Collection BagSequence SetOrderedSet OCL allows you to treat any instance like a collection. You can ask if a single attribute is empty.

Collections must by Typed Set(Bid) Bag(String) Like generics in Java or templates in C++.

Collections Literals Use curly brackets around comma lists to specify Collection literals. Bag {‘sock’, ‘sock’, ‘shirt’, ‘sweater’, ‘sock’} Sequence {‘abe’, ‘bob’, ‘bob’, ‘tim’, ‘zak’} Set {16.0, 2.0, 64.0, 8.0, 128.0, 3.5} OrderedSet {1, 2, 4, 8, 16, 32, 64, 128} You can also specify Collections of Collections.

Basic Collections Operations a : Set(String)b : Stringc : Set(String) a = ca <> c a->size()a->count(b) a->excludes(b)a->excludesAll(c) a->includes(b)a->includesAll(c) a->isEmpty()a->notEmpty() a->sum()-- contents are of type supporting +

More Collections Operations OCL supports a wide range of Collection operations that vary by Collection type. first(), last(), at(i : Integer), etc. for {ordered} collections union(), -, asSet(), including(), symmetricDifference(collection : Collection) are a sample

Flatten Recursively adds the members of nested collections to a single collection. context MyType def: a : Set(Set(Integer)) = Set {Set{1, 2, 3}, Set{3, 4, 5}, Set{4, 5, 6}} a->flatten() = Set{2, 3, 1, 5, 4, 6} -- no order

Collection Loops OCL supports an iterate() operation for Collections. On top of that idea, OCL provides a set of Collection operations that accept expression. Examples: any(expression)exists(expression) collect(expression)one(expression) select(expression)reject(expression)

Other OCL Types OclAnythe root Type OclVoidthe “null” Type “undefined” OclTypea type, like “Class” in Java OCL provides operations for type identification. Tuplegroup of named values Tuple {name : String = ‘Dan’, role : Role = Role::Speaker}

OCL Topics OCL Basics The LiquidLemons Example OCL in Together Team Modeling Exercise

Liquid Lemons Domain

LL Invariants context Sale -- a Sale has one or more items inv numberOfSaleItems : items->size() > 1 -- a Sale's subtotal may not be less than zero inv subtotalGreaterThanZero : subtotal().amount > 0.0 and subtotal().currency = Currency::USDollars

LL Pre and Post context LiquidLemons::addLemonade(flavor : Flavor, size : DrinkSize) pre activeSale : currentSale->size() = 1 pre mustHaveFlavor : not flavor.oclIsUndefined() pre mustSpecifySize : not size.oclIsUndefined() post newLemonade : currentLemonade->size() = 1

LL Query

Collections Queries context ItemAnalyzer::averagePrice() : Money body: items.basePrice()->sum() / items.basePrice()- >size() context ItemAnalyzer::uniqueModDescriptions() : Set(String) body: items.modDescriptions() ->flatten()->asSet()

Composite Queries Use small methods with single responsibilities to build up larger functions. -- the total we want is subtotal plus tax context Sale::total() : Money body: subtotal() + tax() -- tax is the subtotal times the local tax rate context Sale::tax() : Money body: subtotal() * Tax::localRate

Composite Queries Cont. context Sale::subtotal() : Money body: items.price()->sum() context LineItem::price() : Money body: basePrice() + modsPrice() context LineItem::modsPrice() : Money body: modifiers.price()->sum()

Don’t Do This context LineItem::basePrice() : Money body: if size = DrinkSize::Small then if flavor = Flavor::Regular then Money::newInstance(1.23, Currency::USDollars) else Money::newInstance(1.73, Currency::USDollars) endif else if flavor = Flavor::Regular then Money::newInstance(2.43, Currency::USDollars) else Money::newInstance(3.13, Currency::USDollars) endif

Use Polymorphism Little policy classes are an extension of the little operations idea. Smaller rules are easier to read. context LargeRegularLemonade::basePrice() : Money body: Money::newInstance(2.43, Currency::USDollars) context SmallFlavoredLemonade::basePrice() : Money body: Money::newInstance(1.72, Currency::USDollars)

OCL Topics OCL Basics The LiquidLemons Example OCL in Together Team Modeling Exercise

Where Does the OCL Go? Use the named property fields and boxes. Shows up in generated docs and XMI export. Not visible in diagrams.

OCL Notes Attach notes containing OCL to correct contexts. OCL is visible in the diagrams. Potential to clutter the model.

Together Designer Syntax checked OCL in “Constraint Notes” that establish context. Now in field test.

OCL Topics OCL Basics The LiquidLemons Example OCL in Together Team Modeling Exercise

Domain Options Tic-Tac-Toe Ants Electronic Voting Poem Golf Turtle Logo Dog Kennel