DOC PREVIEW
Toronto CSC 340 - The Object Constraint Language

This preview shows page 1-2 out of 6 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 6 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Page ‹#› 2003 John Mylopoulos Object Constraint Language -- 1Information Systems Analysis and Design CSC340The Object Constraint Language (OCL)The Object Constraint Language (OCL)ExamplesExamplesInvariantsInvariantsSet-Theoretic ConstraintsSet-Theoretic ConstraintsPre-/Post-ConditionsPre-/Post-ConditionsXI. The Object Constraint LanguageXI. The Object Constraint Language 2003 John Mylopoulos Object Constraint Language -- 2Information Systems Analysis and Design CSC340The Object Constraint LanguageThe Object Constraint LanguageI Some constraints can be adequately expressed in the graphicallanguage (e.g., multiplicity of an association).I Some can not. For example, constraints within operationspecifications (pre- and post-conditions)I The Object Constraint Language (OCL) provides a formallanguage for specifying constraints which can supplement themodels created in terms of UML diagrams.I The language has a precise syntax that enables theconstruction of unambiguous statements.I Each expression has an associated context, which is usuallythe class to which the expression is attached.Page ‹#› 2003 John Mylopoulos Object Constraint Language -- 3Information Systems Analysis and Design CSC340OCL ExamplesOCL Examples 2003 John Mylopoulos Object Constraint Language -- 4Information Systems Analysis and Design CSC340InvariantsInvariantsIInvariants can be associated with classes and describe propertiesthat must hold true for all the instances of the class.I For example, for an LCBO store with a customer database,represented by a Customer classCustomerage ≥ 18says that every customer must have an age attribute value greaterthan 18.I For a CustomerCard class, the invariantsCustomerCardvalidFrom.isBefore(today)expiresAt.isAfter(today)make sure that the card is valid at the time of use.Page ‹#› 2003 John Mylopoulos Object Constraint Language -- 5Information Systems Analysis and Design CSC340More on InvariantsMore on InvariantsI Instead of writingvalidFrom.isBefore(today)we can writevalidFrom --> isBefore(today)isBefore is a binary operation associated with dates.I Sometimes the value of one attribute can be computed from those ofothers (derived attribute):CustomerprintedName = firstName.concat(lastName) 2003 John Mylopoulos Object Constraint Language -- 6Information Systems Analysis and Design CSC340Invariants Between ClassesInvariants Between ClassesI We can also specify invariants between the instances of two ormore classes.I For example, the Customer class may have an invariantcard.customer = customerWe assume here that card is an attribute of Customer andcustomer is an attribute of CustomerCard, and we want tomake 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 CustomerCardshould be the same with the concatenation of customer.nameand customer.title.Page ‹#› 2003 John Mylopoulos Object Constraint Language -- 7Information Systems Analysis and Design CSC340Set-Theoretic ConstraintsSet-Theoretic ConstraintsI Attributes are single-valued in UML, but associations are not (unlesstheir multiplicity specifies so.) We want to define constraints on sets ofobjects too.I For example, if we have a class GoodCustomer which aspecialization of Customer, and Customer has an associationbought with an attribute amount,then we may want a constraintbought.amount --> sum ≤ $5000which says that the sum of all products bought by a good customer isgreater than $5K.I One-product customers have the constraint bought --> size = 1 (or, bought.size = 1) 2003 John Mylopoulos Object Constraint Language -- 8Information Systems Analysis and Design CSC340Set-Theoretic Functions and PredicatesSet-Theoretic Functions and Predicatessize(set) - returns the size (cardinality) of the setsum(set) - returns the sum of the set (assumed to contain numbers)average(set) - returns the average of the setmin(set) - returns the minimum of the setmax(set) - returns the maximum of the setnotEmpty(set) - true if the set is not emptyincludes(object) - true if the set includes the objectunion(set) - returns the union of two setsintersection(set) - returns the intersection of two setsPage ‹#› 2003 John Mylopoulos Object Constraint Language -- 9Information Systems Analysis and Design CSC340I Pre-condition and post-condition expressions are associated to anoperation/method and they describe What must be true before the operation is executed (pre-condition); What will be true once the operation is executed (post-condition).I For example, we may want to say: Customer::buy(product)pre: acctBal-product.price > 0post: acctBal = acctBal@pre - product.pricePre- and Post-conditions in OCLPre- and Post-conditions in OCLThe value of acctBal before the operation 2003 John Mylopoulos Object Constraint Language -- 10Information Systems Analysis and Design CSC340What Does the Post-Condition Mean?What Does the Post-Condition Mean?CreativeStaff StaffGrade :CreativeStaff :StaffGrade :StaffGrade New staff gradegrade :Grade previousGradestartDate:...[Bennett99, p192]Page ‹#› 2003 John Mylopoulos Object Constraint Language -- 11Information Systems Analysis and Design CSC340Pre- and Post-ConditionsPre- and Post-ConditionsCreativeStaff::changeGrade(newGrade:StaffGrade, gradeChangeDate:Date)pre: grade->notEmpty gradeChangeDate >= today (assumes no retroactive changes)post: grade = newGradegrade.previousGrade = [email protected]= gradeChangeDate 2003 John Mylopoulos Object Constraint Language -- 12Information Systems Analysis and Design CSC340Additional ReadingsAdditional ReadingsI [Warmer99] Warmer, J. Kleppe, A. The Object Constraint Language:Precise Modeling with UML, Addison-Wesley 1999.I


View Full Document

Toronto CSC 340 - The Object Constraint Language

Documents in this Course
Scoping

Scoping

10 pages

Load more
Download The Object Constraint Language
Our administrator received your request to download this document. We will send you the file to your email shortly.
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 2 2 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?