Java Reference
In-Depth Information
The generated code checks to see if the OCLExpression for this derivation
has been created already; if not, it initializes it by retrieving the statement from
the EAnnotation and its detail with key derive . Then the expression is evalu-
ated and the list of Topic elements is returned.
As mentioned in the article, some improvements could be made to this
approach, but it illustrates the usefulness of adding OCL statements to your EMF
models. It's not hard to imagine how a significant portion of an application could
be generated from a model adorned with OCL for invariant constraints, method
bodies, and derived features. In GMF, we can see how OCL is used to augment
the diagram-mapping model to provide for constraints, feature initialization,
audit definition, and model metric definition.
BEST PRACTICE
Adding constraints and validation is essential in model-driven software
development. Although you can place validation code within QVT, Xpand
templates, and so on, it's most useful to ensure that your model instance is
well formed when created, or before moving to a model transformation.
3.2.5 Dynamic Instances
A powerful feature of EMF, and one that is useful to a Toolsmith developing a
new DSL, is the capability to create dynamic instances of a model. The reflective
framework of EMF is leveraged to allow instantiation of a model element with-
out generating code beforehand. This can be done from within the default Ecore
editor by selecting an element and choosing the Create Dynamic Instance
context menu item. The instance is stored in an XMI file within the development
workspace, so the generation or launch of plug-ins is not required to test a model
or, more importantly, to test Xpand templates and QVT transformations under
development. This is one important distinction when comparing JET to Xpand.
Dynamic instances are used in the context of our sample projects.
BEST PRACTICE
Use dynamic instance models for development as much as possible. Xpand
templates, QVT transformations, and the OCL console can all work with
dynamic instance models and avoid making Toolsmiths generate code and
 
Search WWH ::




Custom Search