I have more than 13 years experience in MDD, MDA and code generation. Specifically the solution I built and use since more than 12 years is based on MOF 1.3/1.4, UML 1.3, XMI 1.1/1.2 using the NetBeans MetaData Repository (MDR) as the only free and working standard implementation and able to be integrated with other tools.
Reviewing the MOF M2T 1.0 standard published on OMG site
The problem: My experience shows that a code generation framework like MOF M2T:
- It should provide powerful text parsing and formatting features.
For example: page 4 shows an example to generate a Java class with some attributes, just putting their names in the output. In practice:
- the names of the classes and attributes rarely would be formatted as of the common Java naming conventions (and in PIM they should not obey them), which state that for each attribute set/get methods might be generated in the format: get<attribute name with first capital letter> (OK, the referred toUpperFirst() function could help here)
- the common naming pracices for databases map the class attributes to fields where the separate words in the attribute name are all in upper case and separated by ‘_’ i.e. the testAttribute is mapped to TEST_ATTRIBUTE column in the DB. The same is for class names and table names. Does M2T allow easily implementing this feature and easily maintaining it, considering the fact that in a real project it will be used many hundreds of times? I do not see features to create common functions / methods (other than macro with no result)
- It should provide means to organize the templates in a reasonable and easy to follow way. The structure of the models or metamodels to traverse is complex in MOF 1.4 & UML 1.3, it is incredibly more complex in MOF 2+ UML 2+. In such situations the procedural approach becomes complex and hard to maintain. In addition those structures are object-oriented i.e. use inheritance and polymorphic behavior. Thus, the object-oriented approach to creating the M2T template language would be more-appropriate to support object-oriented structures matching the structure of the metamodel of the modeling language to generate from.
- The template language should allow extracting common logic / procedures (macros) and functions outside the templates and sharing the same logic in many templates. The best place would be a structure of classes, corresponding to the metamodel to process.
- The template language should allow using control structures outside the templates themselves and initiate/apply them on model objects or results of queries on the model (i.e. collections of objects).
- It seems to me that a more imperative approach to applying the templates than just using the types of the templates parameters would be easier to understand and maintain. Again, in a real case there are tens of templates nesting in each other, so maintaining implicitly their dependencies might be a real obstacle.
- Honestly, I think that it is too easy to implement some logic in an M2T template and then copy it hundred of times, which would make the support a real nightmare.
About the normative example on page 27 and further:
- The sample model to generate the DB description shows the primary and foreign keys as separate instances:
- this is obviously a PSM, but the real benefits of MDA are gained when starting from PIM (there are no PK and FKs) and the generation of the intermediate PSM is a really rare practice. Many tools use the PIM and generate the code, scripts, DB schemas, deployment descriptors, etc. out of it. This both imposes more requirements on the M2T features (as of above) and just narrows the area of M2T application in its current state.
- the example is deceptive, because it assumes that the class and attribute names will be the same as the table and field names. In real practice (see above) there are different naming schemas and in addition some DBs (like Oracle) impose maximum name length restrictions. In a complex model there may be overlapping names of FK constraints, sequence names, field names when reducing / abbreviating them from the human-readable PIM.
- Example 3 on page 30 demonstrates the weaknesses in the generation of the set/get method names – try the Java code conventions.
- Examples 1 and 3 are deceptive because they just generate attributes, but do not show the complexity of associations support methods – try the generation of associations support methods for the cases of uni-directional and bi-directional associations in 1:1, 1:M and M:N multiplicity (not mentioning their composition and aggregation kinds). In the real case example I am working with there are 8 templates to generate such.
I hope these comments would help to improve that standard.
With best regards
(sent to OMG M2T task force, no response)