10.3 Packaging Expressions


Like every other model element, OCL expressions may be included in a package. In general, the model element that is the context of an OCL expression is the owner of that expression, and the expression will be part of the same package as its context. When the expression is present in a diagram, it is obvious that the package that owns the expression is the package that owns its context. Because expressions are often written separate from the diagrams, it is not always clear to which package they belong.

To specify explicitly the package in which an OCL expression belongs, you have two options. The context definition may contain a pathname indicating the package to which the context belongs, or the context definition may be enclosed between package and endpackage statements. These statements have the following syntax, where the boldface words are keywords:

  package  Package::SubPackage  context  X  inv  : ... some invariant ...  context  X::operationName(..)  pre  : ... some precondition ...  endpackage  

The preceding example has the same meaning as the following two expressions:

  context  Package::SubPackage::X  inv  : ... some invariant ...  context  Package::SubPackage::X::operationName(..)  pre  : ... some precondition ... 

An OCL file (or stream) may contain any number of package statements and any number of expressions enclosed in context definitions, thus allowing all invariants, preconditions, and postconditions to be written and stored in one file. This file may coexist with a UML model containing the diagrams as a separate entity.



Object Constraint Language, The. Getting Your Models Ready for MDA
The Object Constraint Language: Getting Your Models Ready for MDA (2nd Edition)
ISBN: 0321179366
EAN: 2147483647
Year: 2003
Pages: 137

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net