My Blog

...

Customizing UML With XCore

With the latest version of XCore (EMF 2.9.1 and XCore 1.0), it is now possible to easily customize the UML meta-model.

As shown in the code below, we just have to import classes from the UML meta-model and declare new classes that extend them.

book.xcorelink
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import org.eclipse.uml2.uml.PackageableElement
import org.eclipse.uml2.uml.Element
import org.eclipse.uml2.uml.Node
import org.eclipse.uml2.uml.ExecutionEnvironment

class BookElement extends PackageableElement {

        refers Element documentation
}

class Book extends BookElement {

        contains Part[] parts
}

// ...

Why using this technique instead of UML Profile?

Even though the UML Profiles technique is qualified as lightweight in this article, UML Profiles has some major drawbacks:

  1. Before modeling, the end-user has to understand the concepts in the UML meta-model and then the concepts declared in the UML Profile.
  2. During modeling, the end-user has to instantiate a UML meta-class and then to apply a stereotype on that instance; quite tedious process and not very intuitive.
  3. It is even worse for the one that defines the UML Profile and develops tools based on it: he has to jump between stereotypes and UML meta-classes, he cannot get a consistent view on stereotyped instances.

We don’t have these drawbacks with the XCore technique. But it introduces other issues / limitations:

  • It is probably not compatible with UML drawing tools.
  • The implementation classes generated by EMF extend UML implementation classes which are private in the UML bundle; it is just a warning but it works.

Why Keep UML?

Often, when we start modeling a DSL, we don’t think that you need UML; it is rather the opposite: we want to get rid of UML. But on the long run, when the DSL evolves, we realize that we need common features / concepts such as

  • Namespace / NamedElement for naming elements
  • Package / PackageableElement for categorizing elements
  • etc.

Comments