Information Systems Analysis and Design CSC340 Information Systems Analysis and Design The Constraint Language XIII A Constraint Language for UML I The Constraint Language CL Sets and Bags Selectors and Invariants Examples Pre Post Conditions I I I 2004 John Mylopoulos Constraint Language 1 Information Systems Analysis and Design CSC340 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 Information Systems Analysis and Design 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 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 I I Constraint Language 4 Information Systems Analysis and Design Contexts for CL Expressions I CSC340 CL Expressions Objects Bags and Sets I CSC340 CSC340 Selectors in Action 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 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 5 2004 John Mylopoulos Page Constraint Language 6 Information Systems Analysis and Design CSC340 Information Systems Analysis and Design CSC340 nil and empty Sara Person 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 employment IBM Company Robert Person employment employment president Jianguo Person Constraint Language 7 Information Systems Analysis and Design CSC340 2004 John Mylopoulos employment IBM Company Robert Person employment employment CIBC Company employment Sara IBM Robert CIBC Lin CIBC Jianguo CIBC Lin CIBC Person age income sex employment 0 0 1 husband spouse friend wife 0 1 0 president Jianguo CIBC 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 X Lin Person CSC340 Selectors for Symmetric Associations Associations 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 Constraint Language 8 Information Systems Analysis and Design Associations are Sets of Tuples I CIBC Company employment Lin Person president Jianguo Person 2004 John Mylopoulos Constraint Language 9 Information Systems Analysis and Design CSC340 2004 John Mylopoulos Information Systems Analysis and Design wife Sara Person Robert Person friend I friend Robert Lin Jianguo Lin Lin Maria friend friend Jianguo Person 2004 John Mylopoulos Maria Person Constraint Language 11 bag attrName obj obj attrName bag I bag assocName obj assocName I bag roleName obj roleName I spouse Robert Sara Lin Person CSC340 Applying Selectors to Bags Sara spouse Robert Lin friend Robert Jianguo Maria Maria friend Lin husband Constraint Language 10 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 Page Constraint Language 12 Information Systems Analysis and Design CSC340 Information Systems Analysis and Design Constraints Composition of Selectors I I CSC340 Constraints or invariants describe properties that must hold true for all the instances of the class 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 Person age income sex 0 0 1 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 13 Information Systems Analysis and Design CSC340 2004 John Mylopoulos Information Systems Analysis and Design I If x is the wife of y then y is the husband of x notEmpty wife implies self self wife husband or I 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 Popular persons have more than 50 friends We define a
View Full Document
Unlocking...