UML <-> Erlang
Eric Newhuis
enewhuis@REDACTED
Mon Nov 17 15:44:46 CET 2003
Well for starters...
I'm not sure I understand the mismatch between OO and Erlang. OO to me
is a way of thinking about design. And Erlang is a specific
programming language. There seem to be many things from the OO
perspective that are realized perfectly in Erlang.
Even OO has modeled the notion of a process. An "active object", as it
has been called, is an object with its own local thread of control.
This has been explained previously as a class that has a constructor
that starts a thread that executes the "real code" while the class
interface functions post messages onto the thread's message queue for
dispatching. Thus methods can execute asynchronously w.r.t each
instance/object.
Taking an approach like this it would be a simple matter to port the
"structure" of Erlang code to C++. (Not too sure about the functional
bits. Replacing pattern matching and LCO with C++ counterparts would
be almost but not quite the exact opposite of pleasure.)
One can model active objects in UML. Perhaps one should even declare a
stereotype <<ActiveObject>> to denote such classes in the design.
Then, whenever one sees one of these <<ActiveObject>> stereotypes in
the design one knows that one is (potentially) dealing with an
asynchronously communicating parallel process (methods can still be
synchronous or asynchronous case by case).
Incidentally one of the reasons I decided to use Erlang was because I
understood the ActiveObject pattern and I was thrilled to see how easy
it was to implement in Erlang. Most of our code is like an
ActiveObject. A gen_server is an ActiveObject.
Erlang is far more general purpose, however, and so if I would like to
communicate design intentions less ambiguously I should use a
stereotype. ActiveObject seems to carry the same implications both in
C++ and Erlang. And I can use UML to assist in the design of either
approach.
I think UML through association with specific OO programming languages
may have left its more theoretical roots. Grady Booch, one of the
early men behind UML has long supported the asynchronous communicating
process concepts in his design methodology. Hopefully those interested
in UML can still find those aspects that suit UML well for this mode of
thinking.
-e
> There may be an impedance mismatch between UML (object-oriented) and
> Erlang (functional and process-oriented). Not to say that it is
> impossible, but to say that several different approaches to map UML
> and Erlang could be equally valid.
> The best I think would be to start from example, like yours maybe, and
> see what it would give in UML. Then to generalize and define precise
> mapping rules, that could be implemented in a tool. I am curious to
> see examples of the mappings you have in mind.
More information about the erlang-questions
mailing list