Last Updated:

M2M - Using Inheritance

Andy Lapping

Lately I've been working a lot with Model-to-Model Transformation (M2M) - an extremely powerful capability from Sodius Willert that that allows rule-based transformation of a model from one domain to another, or from a model directly to a ‘text’ file, for example XML (which might also be domain specific such as ARXml from the Automotive domain).

You could, for example, take an enterprise-level UAF (Unified Architecture Framework) model and transform part of it down to SysML (Systems Modeling Language) for further development. You could take a system engineering model in SysML and transform part of it down to UML (Unified Modeling Language) for further development at the software level. What’s more the rules themselves are model-based and captured in Rhapsody.

There is online help and I wrote a Quick Start hands-on lab to help you get started, but the more I work with M2M the more I discover (and a lot of it is undocumented !)

This is the first in a series of things I wish I knew before I started building my rules.

M2M rulesets may inherit from each other which lends itself to two use cases:

Common Rules

If you have rules that are common to several different rulesets, then they may be stored in a common ruleset that the others inherit from. For example, in the automotive domain, AUTOSAR has two variants – Classic and Adaptive but there is some commonality between them such as the typing mechanism. In this case transformation rules that are common may be kept separately:

Maintaining a Single Source of Truth

The second use for this mechanism is not so obvious. 

When you want to run an M2M transformation, any choices you make (such as which packages in the model to include) are stored on the ruleset. This means that the ruleset has to be read-write, which means you end up with a copy of the rules in every project you use them in. If you add them by reference, then any choices you make are discarded. You might think that adding the rules as an editable reference is a solution – but it isn’t. Any changes you make when running an M2M transformation will then be stored for everyone else who uses the same ruleset on their models.

The solution is to use inheritance. Add a new ruleset to your model and inherit from the set of rules you want to use as illustrated below where the green boxes are added as REF whilst the orange box is a new set of rules:

That new ruleset might be completely empty, or it may have additional information such as which packages in this model to retain. Moreover, when you run M2M on that ruleset, all your choices are stored there without needing to modify the actual set of rules being used. This is what it looks like in Rhapsody:

Running M2M on TransformToClassic will include the rules from SysML2AUTOSARClassic and the rules from SysML2AUTOSARCommonRules.

It helps if you know in advance that you might have common rules of course, but in the above example I developed the Classic and Adaptive rules separately and then consolidated them when I realized how much I could re-use between the two.