Unformatted text preview:

Information Systems Analysis and Design CSC340 XIII A Constraint Language for UML The Constraint Language CL CL Sets and Bags Selectors and Invariants Examples Pre Post Conditions 2004 John Mylopoulos Constraint Language 1 Information Systems Analysis and Design CSC340 The Constraint Language I I I I Some constraints can be adequately expressed graphically e g multiplicity of an association Some can not For example constraints within operation specifications pre post conditions The Object Constraint Language OCL Warmer99 is a formal language for specifying constraints for UML class diagrams We present a syntactic variant of a subset of OCL let s call it Constraint Language CL for short 2004 John Mylopoulos Constraint Language 2 Page Information Systems Analysis and Design CSC340 Objects Bags and Sets I I I I Objects are instances of classes including predefined classes Integer Number and String Bags include zero or more objects and or sets and or other bags possibly with duplicates and no assumed order e g tom maria tom sara maria tom maria tom Two bags are equal iff they have the same number of the same elements tom maria tom sara maria tom maria sara Sets are bags with no duplicates 2004 John Mylopoulos Constraint Language 3 Information Systems Analysis and Design CSC340 CL Expressions I I CL expressions define constraints or invariants for classes which must be try for all their instances e g every employee earns less than his CEO CL expressions also define conditions that must be true before an operation can be executed preconditions and conditions that must be true after postconditions e g Before withdrawCash acct amount it must be that acct balance amount precondition Or After withdrawCash acct amount is executed it must be that acct balance new acct balance old amount postcondition 2004 John Mylopoulos Constraint Language 4 Page Information Systems Analysis and Design CSC340 Contexts for CL Expressions I I I Every expression has a context which is the class within which it is defined The special identifier self refers to an instance of the class within which it appears The most basic CL expressions are called selectors and they return an object or a bag 2004 John Mylopoulos Constraint Language 5 Information Systems Analysis and Design CSC340 Selectors in Action Person age income sex employment 0 1 employer employee 0 1 president 1 0 Company name addr sales Expressions appearing here self addr or just addr returns addr of a particular company self employment returns the set of all employees self employee returns the set of all employees as well self president returns the singleton set of presidents self employment set of all employers of a person self employer set of all employers of a person 2004 John Mylopoulos Constraint Language 6 Page Information Systems Analysis and Design CSC340 nil and empty I I I I I When an attribute attr has no value for object obj then obj attr returns nil no value When there are no associated objects to an an object obj through association assoc or role rl then obj assoc and obj rl return the empty bag or empty Note nil Moreover nil Sara nil nil Sara etc This means that if Sara age nil George age nil then Sara age George age 2004 John Mylopoulos Constraint Language 7 Information Systems Analysis and Design CSC340 Sara Person employment IBM Company Robert Person employment employment CIBC Company Lin Person employment president Jianguo Person 2004 John Mylopoulos Constraint Language 8 Page Information Systems Analysis and Design CSC340 Associations are Sets of Tuples I You can think of associations as sets no duplicates of tuples Sara employment IBM CIBC employment Robert Lin Jianguo CIBC employee Robert Lin Jianguo CIBC employer syntax error Sara Person employment IBM Company Robert Person employment employment CIBC Company Lin Person employment Sara IBM Robert CIBC Lin CIBC Jianguo CIBC Lin CIBC president Jianguo CIBC X employment president Jianguo Person 2004 John Mylopoulos Constraint Language 9 Information Systems Analysis and Design CSC340 Selectors for Symmetric Associations Person age income sex 0 0 1 husband spouse friend wife 0 1 0 self age or just age returns the age of a particular person self husband returns the set of all husbands self wife returns the set of all wives self spouse returns the set of all husbands and wives self friend returns the set of all friends 2004 John Mylopoulos Constraint Language 10 Page Information Systems Analysis and Design CSC340 Sara spouse Robert Lin friend Robert Jianguo Maria Maria friend Lin wife Sara Person husband friend Robert Lin Jianguo Lin Lin Maria Robert Person friend spouse Robert Sara Lin Person friend friend Maria Person Jianguo Person 2004 John Mylopoulos Constraint Language 11 Information Systems Analysis and Design CSC340 Applying Selectors to Bags I bag attrName obj obj attrName bag I bag assocName obj assocName I bag roleName obj roleName I obj bag obj bag For example suppose Sara friend Robert Lin Jianguo friend Robert Maria Sara Jianguo friend Robert Lin Robert Maria Sara Jianguo Sara friend Robert Lin Robert Maria Robert Lin 2004 John Mylopoulos Constraint Language 12 Page Information Systems Analysis and Design CSC340 Composition of Selectors I I Selectors can be composed self sel1 sel2 self sel1 sel2 means that we take the value of self sel1 either a single value or a bag and we apply to it sel2 For example self friend income returns the bag of all income values of objects in the bag self friend e g if self friend Tom Maria Sara and their incomes are respectively 16K 19K and 16K then self friend income 16K 19K 16K 2004 John Mylopoulos Constraint Language 13 Information Systems Analysis and Design CSC340 Constraints Constraints or invariants describe properties that must hold true for all the instances of the class Person 0 0 1 age income sex husband spouse friend wife 0 1 120 age 0 income 100M 0 But also not empty wife implies wife sex female not empty husband implies husband sex male 2004 John Mylopoulos Constraint Language 14 Page Information Systems Analysis and Design CSC340 More Invariants I If x is the wife of y then y is the husband of x notEmpty wife implies self self wife husband or Forall y includes self wife y implies includes y husband self I The president of a company is also its employee includes self employee self president 2004 John Mylopoulos Constraint Language 15 Information Systems Analysis and Design CSC340 More I I Popular persons have more than 50


View Full Document

Toronto CSC 340 - A Constraint Language for UML

Documents in this Course
Scoping

Scoping

10 pages

Load more
Loading Unlocking...
Login

Join to view A Constraint Language for UML and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view A Constraint Language for UML and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?