Building a Language Using MOF

As we wrote in Chapter 4, the M3 level at which MOF resides is a model of the simplest set of concepts required to capture models and metamodels, which means that MOF is the surefire way to define metamodels. So long as you only use the set of constructs defined by the MOF which, while simple, are certainly powerful enough to capture the static structure of a model you can define the abstract syntax of any modeling language.

If you're familiar with the UML, you're already familiar with the most important concepts of the MOF. Indeed, the UML core is a superset of the MOF metamodel in MOF 2.0 and UML 2.0.

MOF offers five important concepts that you can use to define a language:

  • Types (classes, primitive types, and enumerations)

  • Generalization

  • Attributes

  • Associations

  • Operations

Figure 7-1 shows the fragment of the UML metamodel that defines a class Comment. This class allows us to create those little sticky notes that we can attach to model elements. As such, Figure 7-1 is a UML model (of the UML).

Figure 7-1. Excerpt of UML metamodel in MOF


Figure 7-1 is also a MOF model because it uses only the limited constructs we listed above that are allowed in MOF. Moreover, because the MOF has no concrete syntax, we have expressed the model using UML notation, though we could have chosen any notation at all.

By design, the UML metamodel is expressed entirely using the MOF subset, so any example model fragment would have qualified as a MOF model.

However, if you were to build a model in UML using, say, an association class, that model would be UML only, and you would have to transform it into the simpler constructs of the MOF for it also to be a MOF model. The association class could be re-expressed as an ordinary class with two separate associations to the primary classes, and this would then conform.

Given the UML as a concrete syntax for MOF, building a MOF model is really "just" building a UML model with a more restricted abstract syntax. Now all you have to worry about is figuring out what the appropriate conceptual entities in your language need to be.

Of course, it's also possible to reuse the whole UML metamodel or parts thereof to derive your own variant. If you're happy with most parts of the UML, but you've always been missing this one concept that you wished the UML designers had thought of, you can create a copy of the UML model and modify it. Although you're diverting from the UML standard, you are reusing a proven modeling language, which is more effective than designing your own language from scratch.

MDA Distilled. Principles of Model-Driven Architecture
MDA Distilled. Principles of Model-Driven Architecture
ISBN: B00866PUN2
Year: 2003
Pages: 134 © 2008-2017.
If you may any questions please contact us: