What can UML do for you?

Do you know what UML can do for you? I mean, did you know that UML models can actually do things?

One of the least known features of UML is that you can model detailed imperative behavior. The UML “instruction set” can do things like:

  • create and destroy objects
  • create and destroy links (associations) between objects
  • read and write attributes and local variables
  • invoke operations and functions
  • throw and catch exceptions
  • conditional statements
  • loops

That is quite amazing, isn’t? And all that while still preserving a high level of abstraction. Such capability is generally referred to as ‘action semantics’. Action semantics provides the basic framework for executability in UML and has been there for quite a while now. It was originally added to the spec, first as patch, in UML 1.5 (2003), and then more seamlessly integrated into UML 2.0 and following spec releases.

Action Semantics and TextUML

An even more well-kept secret is that the TextUML notation supports UML action semantics and thus the creation of fully executable UML models. This support is not yet shipped as part of the TextUML Toolkit, but will be in the next release. Meanwhile, if you want to give it a try or take a closer look, you will have to grab the source from the SVN repository.

I plan to go into more details in the near future, but just to wet your appetite, here is one example of an executable UML model described in the TextUML notation:

package hello;

apply base_profile;
import base;

class HelloWorld
    static operation hello();
        Console#writeln("Hello, World");


Cool, isn’t? If you had a UML runtime, this model could be executed even before you made a decision about what platform to target. Also, if your code generator were action semantics aware, you could trigger code generation for the target platform(s) of choice, with the key difference that you could achieve (or get very close) to full code generation, as the model now also describes behavior. No more of that monkey business of having to edit the generated code and manually fill in all those /* IMPLEMENT ME! */ methods.

Do you think this has value? Would you want to work with a tool that supported that? I am really keen on knowing your opinion.


6 thoughts on “What can UML do for you?

  1. Ed Merks

    November 3, 2008 at 7:36am

    If only we had this for Ecore instead. Given that we already have an efficient Ecore-based runtime, it seems more immediately applicable… Goodness knows Emfatic needs some love and attention…

  2. rafael.chaves

    November 3, 2008 at 8:51am

    Ed, correct me if I’m wrong, but EMF’s runtime capabilities are limited to structural features (data), no support for behavior. That sort of thing cannot be done at the tooling level, the metamodel itself has to support it. That is bound to lead to a heavy metamodel, which is the opposite of EMOF/Ecore’s reason-d’être. Unless you go with unparsed text, but that is more or less the same as ignoring the issue altogether and pushing it to the application.

  3. Ed Merks

    November 3, 2008 at 9:50am

    Rafael, EMF has EOperations but no mechanism for declaring their behavior nor for invoking them reflectively, i.e., EOperations just declare the signature. I’ve been prototyping designs for https://bugs.eclipse.org/bugs/show_bug.cgi?id=216701 and thinking about similar mechanisms to describe the behavior of an operation along with the ability to reflectively invoke an EOperation. We do already support specifying the text of the Java method body, but I’d like something that would work for dynamic models. So yes, I’m imagining indeed using unparsed text, but to me that’s “just” an XMI serialization story. The runtime story would be that expression languages are pluggable.

    I think you’re exploring an area that’s becoming increasingly interesting and relevant. It just seems that building a runtime model for UML is a pretty challenging task in and of itself and that this is a prerequisite for the rest of the story. While adding something to an Ecore base could produce useful and used results every quickly…

  4. bnz

    November 7, 2008 at 4:06am

    Huh. Interesting. Never heard of “action semantics” in the context of UML. Could you please provide me with a pointer in what OMG standard i have to look this up? A quick search through the superstructure and infrastructure standard did help much. I would be very glad to read a little more about that.

  5. rafael.chaves

    November 7, 2008 at 9:33am

    The specification itself does not refer to it as ‘action semantics’.

    It is basically the chapter on Actions. The Superstructure has it since 2.0 (in 2.1.1, it is in chapter 11). In 1.5, it was the entire part 5.

  6. [...] There is no need to mix languages, UML has support for both structural and behavioral modeling (since 2002!). Action languages are not (or don’t have to be) “other languages” [...]

Comments are closed.