4.7 Summary


This chapter has discussed how OCL expressions can be implemented. The translation of the expressions to programming code must be done according to the following steps:

  1. Define the implementation of the UML model elements. Use any manner you like, provided that the choices made can be used in the subsequent steps.

  2. Define the implementation of the OCL Standard Library. Map the OCL basic types to basic types in the target language. Map the OCL collection types to collection types in the target language. When needed, define a separate class with (static) collection operations that cannot be mapped to the collection types in the target language. Map each use of an OCL collection iterator to a specially designed code fragment.

  3. Define the implementation of the OCL expressions. Take care of evaluation order and possible side effects.

  4. Place the code fragments implementing the OCL expressions correctly in the code for the model elements. Define separate operations for each invariant, to be called whenever the invariant needs to be checked.

  5. For invariants, and pre- and postconditions, decide when to check them, and what to do when the check fails. Decide whether the constraints need to be checked during runtime.

OCL is a language that can be used to develop platform-independent models; therefore, many design issues need to be addressed during the translation of OCL to code. Once these decisions are made, the translation process is mostly straightforward. As shown in many of the examples, the OCL code is of a significantly higher level than much of the Java code, making it easier to read and write. This is exactly what is needed when you want to apply MDA techniques to your model.



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