This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: © Eoin Woods, 2005; http://www.eoinwoods.info V1.1, 12 July 2005 page 1 / 6 OCL Quick Reference Eoin Woods, Zuhlke Engineering, July 2005. This document provides a quick reference summary of the Object Constraint Language, as I understand it to be as of the UML 1.5 standard. It should not be taken as a definitive statement of OCL and does not attempt to provide formal semantic definitions. Refer to the Resources section at the end of the document for sources of further information on OCL. Reports of errors and omissions are gratefully received by email to [email protected] . This document is not a product or service provided by Zuhlke Engineering and has no implied warranty or endorsement from Zuhlke. Uses of OCL • Class model invariants ; operation pre and post conditions ; query bodies (definitions). • Definition of guards in statechart models. Basic Points • All OCL expressions are side-effect free. • No statement terminators (“ ; ” or similar). • Comments can be “-- rest of line ” or “ /* block */ ” (latter is OCLE only). • Naming rules are implementation specific, the reference manual simply stating that “ :: ” is used as a scope separator (e.g. package::class::method() ). • The term “operation” refers to a method with side-effects, the term “query” for a method that does not change the state ( state = [email protected] holds in the post-condition). Setting Context To define the model, package and scope of an expression: model my_model –- OCLE specific package my_package context Class1 inv ... (invariant or whatever) context Class1::operation1(v1: Integer) inv ... endpackage endmodel The context can be set to any model element (package, class, interface, component) or some sub- elements such as operation, attribute and in some cases (e.g. interaction diagram) an instance. The reserved name “ self ” refers to the current object (a la “ this ” in C++ or Java). OCLE extends this slightly by allowing context on inner classes to be specified using the syntax “ context Outer.Inner inv inv1 ... ”. © Eoin Woods, 2005; http://www.eoinwoods.info V1.1, 12 July 2005 page 2 / 6 Constraints Can define invariants over model state or sets or pre/post conditions for operations or bodies (i.e. definitions) for queries. Invariants: context Class1 inv attr1 > 100 context Class2 inv secondInvariant: attr2 < 10 Can have as many “ inv ” statements as required, optionally named, and the resulting invariant is their conjunction (“ i1 and i2 and ... ”). Pre and Post Conditions: context Class1::method1(v1: Integer) : Integer pre valueIsLargeEnough: v1 >= 100 post: attr1 >= [email protected] + 100 and result > v/10 The “ @pre ” notation refers to the “before” state (VDM’s “hook” notation) and “ result ” is a reserved word for the result of the operation (if it has one)....
View Full Document
This note was uploaded on 01/15/2011 for the course ECE 6161 taught by Professor Khkjk during the Winter '10 term at Concordia Canada.
- Winter '10