Unformatted text preview:

Information Systems Analysis and Design CSC340 XI The Object Constraint Language The Object Constraint Constraint Language Language OCL OCL Examples Invariants Set Theoretic Constraints Constraints Pre Post Conditions Pre Post Conditions 2003 John Mylopoulos Object Constraint Language 1 Information Systems Analysis and Design CSC340 The Object Constraint Language I I I I I Some constraints can be adequately expressed in the graphical language e g multiplicity of an association Some can not For example constraints within operation specifications pre and post conditions The Object Constraint Language OCL provides a formal language for specifying constraints which can supplement the models created in terms of UML diagrams The language has a precise syntax that enables the construction of unambiguous statements Each expression has an associated context which is usually the class to which the expression is attached 2003 John Mylopoulos Object Constraint Language 2 Page Information Systems Analysis and Design CSC340 OCL Examples 2003 John Mylopoulos Object Constraint Language 3 Information Systems Analysis and Design CSC340 Invariants I I I Invariants can be associated with classes and describe properties that must hold true for all the instances of the class For example for an LCBO store with a customer database represented by a Customer class Customer age 18 says that every customer must have an age attribute value greater than 18 For a CustomerCard class the invariants CustomerCard validFrom isBefore today expiresAt isAfter today make sure that the card is valid at the time of use 2003 John Mylopoulos Object Constraint Language 4 Page Information Systems Analysis and Design CSC340 More on Invariants Instead of writing validFrom isBefore today we can write validFrom isBefore today isBefore is a binary operation associated with dates Sometimes the value of one attribute can be computed from those of others derived attribute Customer printedName firstName concat lastName I I 2003 John Mylopoulos Object Constraint Language 5 Information Systems Analysis and Design CSC340 Invariants Between Classes We can also specify invariants between the instances of two or more classes I For example the Customer class may have an invariant card customer customer We assume here that card is an attribute of Customer and customer is an attribute of CustomerCard and we want to make sure that the values of these attributes match I Likewise for the CustomerCard class we may have an invariant printedName customer title concat customer name which states that the value of printedName of CustomerCard should be the same with the concatenation of customer name and customer title I 2003 John Mylopoulos Object Constraint Language 6 Page Information Systems Analysis and Design CSC340 Set Theoretic Constraints I I I Attributes are single valued in UML but associations are not unless their multiplicity specifies so We want to define constraints on sets of objects too For example if we have a class GoodCustomer which a specialization of Customer and Customer has an association bought with an attribute amount then we may want a constraint bought amount sum 5000 which says that the sum of all products bought by a good customer is greater than 5K One product customers have the constraint bought size 1 or bought size 1 2003 John Mylopoulos Object Constraint Language 7 Information Systems Analysis and Design CSC340 Set Theoretic Functions and Predicates size set returns the size cardinality of the set sum set returns the sum of the set assumed to contain numbers average set returns the average of the set min set returns the minimum of the set max set returns the maximum of the set notEmpty set true if the set is not empty includes object true if the set includes the object union set returns the union of two sets intersection set returns the intersection of two sets 2003 John Mylopoulos Object Constraint Language 8 Page Information Systems Analysis and Design CSC340 Pre and Post conditions in OCL I I Pre condition and post condition expressions are associated to an operation method and they describe What must be true before the operation is executed precondition What will be true once the operation is executed postcondition For example we may want to say Customer buy product pre acctBal product price 0 post acctBal acctBal pre product price The value of acctBal before the operation 2003 John Mylopoulos Object Constraint Language 9 Information Systems Analysis and Design CSC340 What Does the Post Condition Mean CreativeStaff StaffGrade Grade StaffGrade CreativeStaff grade previousGrade StaffGrade Bennett99 p192 startDate New staff grade 2003 John Mylopoulos Object Constraint Language 10 Page Information Systems Analysis and Design CSC340 Pre and Post Conditions CreativeStaff changeGrade newGrade StaffGrade gradeChangeDate Date pre grade notEmpty gradeChangeDate today assumes no retroactive changes post grade newGrade grade previousGrade grade pre grade previousGrade gradeFinishDate gradeChangeDate 2003 John Mylopoulos Object Constraint Language 11 Information Systems Analysis and Design CSC340 Additional Readings I I Warmer99 Warmer J Kleppe A The Object Constraint Language Precise Modeling with UML Addison Wesley 1999 http dec bournemouth ac uk dec ind swebster UML OCL index htm 2003 John Mylopoulos Object Constraint Language 12 Page


View Full Document

Toronto CSC 340 - The Object Constraint Language

Documents in this Course
Scoping

Scoping

10 pages

Load more
Loading Unlocking...
Login

Join to view The Object Constraint Language 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 The Object Constraint Language 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?