5.4 Using OCL to Define Languages


One of the conclusions that may be drawn from the previous sections is that metamodels are simply models. Their only difference is that they reside on another level of abstraction. As OCL is useful in building good models, it is therefore also useful in building good metamodels. When you build a metamodel, you are actually defining a language. Thus, OCL is helpful in defining languages.

In fact, the UML standard was defined using OCL. Approximately two hundred invariants and one hundred operation definitions were written in addition to the diagrams to define the metamodel of UML. In the UML standard, they are called well- formedness rules . The following expression, which refers to Figure 5-3, states that an interface may not have any attributes:

  context  Interface  inv  : features->select(f f.oclIsKindOf( Attribute ) )->isEmpty() 

Even OCL itself was defined using OCL expressions. In the OCL metamodel from Figure 5-4 you can find another example. This one indicates that the source of a loop expression must be a collection, and that the type of the iterator variable must be equal to the type of the elements of the source collection:

  context  LoopExpression  inv  : source.oclIsKindOf( Collection )  inv  : iteratorVariable.type                    = source.oclAsType(Collection).elementType 

Within the MDA framework, new languages will need to be defined, but there is also a need for thorough specifications of existing languages. Most programming languages, for instance, are not formally defined. Usually, the only formal part in their specification is the grammar written in a BNF format. For the rest, its users rely on the compilers and the textbooks . In order to use a programming language as PSM language in the MDA, it needs to be defined with at least the same level of formality as UML. This means that for each PSM language, a definition needs to be built in the form of a UML/OCL metamodel.

New languages can also be defined as so-called profiles to UML. This means that a completely new metamodel for the language is not needed. Instead, the metamodel of UML is used. Extra rules and a mapping of the language concepts to the syntax used are given. The extra rules, of course, should be stated in OCL.

Existing languages can also be fit within the MDA framework using UML profiles. For instance, there is a Java profile [EJB01]. When you use this profile and draw a diagram that looks like a UML class diagram, you have actually created a number of Java classes.



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