2

I am a java software developer/architect and I like UML.

Saying that I also hate the java generated code.

I don't see any value trying to generate the skeleton of my application:

  • creating empty classes is really easy and I don't need a tool to do that
  • also I cannot reuse the generated code because the way it is generated makes it impossible to reuse

The dilemma for me is that my requirements changed so quickly that I need to be able to implement the new demand immediately into an existing code.

My problem is that if I generate my code from my model and then manually develop inside the generated codebase, I cannot generate code again using a model because my modification would be erased.

Except I copy/paste the changes back and forth. That is an enormous effort for too few results. Therefore I do not use MDD but still use a lot UML.

Could UML be successful in a project without MDD code generation ?

I am asking this question because I have a new boss who wants to introduce full MDD process with IBM RSA and today I prefer to have live code and model synchronization or merge with Omondo.

  • Why change a running and proven system?
  • Why systematically generate code from a model while I can do it directly in the code and just merge it later with the model?
  • Why get crap database code generation which cannot even be deployed while I can add stereotype in order to get java annotation and use them with hibernate to generate my database?

One of the reason for boss's change is to get a better project documentation in HTML format. I highly doubt this and think he is looking for more control on delivery and does not know what else to invent!

Other argumentative reasons:

  • Use a product from a large and stable company.
  • Have a full model available which could be deployed in any other language.
    (This is why for me MDD is stupid because it is impossible to deploy on any platform any server, any database just from a model. So why to waste my time?)

Please give me some arguments in order to come back at next meeting and crash this stupid new MDD fan who wants to reorganize the way we work today!

sjas
  • 18,644
  • 14
  • 87
  • 92
UML GURU
  • 1,452
  • 1
  • 9
  • 7

3 Answers3

2

I think your post has the answer in it.

MDD has been plagued with 2 fundamental problems:

  1. An input (modelling language) that is insufficiently expressive to capture the entire problem. Result: you need to complete the specification with another language (code).
  2. The generators - i.e. the rules that convert models to code - are generally incomplete and/or not open for modification by the development team and/or generate poor quality code.

Put those two things together and you get the horrible mess you mention. Consequence: trying to splice together hand-written code with poor-quality generated code. Result: not pretty.

However. Please don't surmise from above that I'm anti-MDD. I'm not - in fact the opposite is true. BUT: the tooling and process need to address the two fundamental issues above.

I've come across /very/ few that do. I used RSA several years ago and it definitely wasn't one of them. (However it's had the intervening time to improve, so it may be there now).

A simple "temperature check" question is to ask whether the tool provides a full Action Language. If it doesn't, it'll fall foul of problem (1). If it fails that, chances are you're in for pain.

If all your boss really wants is good HTML documentation, then simply integrate UMLGraph or apiviz into your build.

So to answer your specific question:

Can UML be used successfully without MDD? Yes. Generally in two ways:

  1. As an informal or semi-formal notation for whiteboard sketching while figuring out the problem and/or solution (what Martin Fowler calls UML as Sketch)
  2. As auto-generated documentation from the code as part of the build process.

Where you'll end up burning unproductive time is creating formal UML diagrams (often with an expensive tool) that have no direct link to the code.

hth.

Community
  • 1
  • 1
sfinnie
  • 9,854
  • 1
  • 38
  • 44
  • 1
    I agree that UML without code is not really productive. What I don't like is model driven code generation from UML and then no more logic between the code and the original model. I think that once the model has been generated you should be able to trace the code and the model relation. In all the MDD tools today once the coede has been generated you don't know which uml element has created this class. The missing feature is the model to java Ids merge and only live code and model tools have this feature. – UML GURU Jan 30 '11 at 11:19
  • 1
    There are two schools of thoughts I think. (1) the model and code are really just 2 different views of the same thing, or (2) the model is in some way more abstract than the code. Neither is universally right or wrong. For (1) I'd agree that you want ongoing synchronisation - not just a "one shot". My preference is (2) - but the tool needs to meet both criteria I listed above. Note also it doesn't have to be UML - see e.g. WebDSL (www.webdsl.org). – sfinnie Jan 31 '11 at 22:01
1

If you cannot control the generation, you are probably using the wrong tools.

What you generate - skeletons or framework specific code - is also depending on the tool. Use tools which allow you to create your own templates.

It is wrong to assume roundtrip engineering will ever work. You cannot transform less detailed model to more detailed code and then back without losing information. One way to solve this would be having same level of details in models as in code, which is not a great thing.

Better approach is to use one way generation from models combined with some good practices for combinening generated and manually written code.

You can use protected regions for manually written code:

  • you specify in template places - e.g. method bodies, which should be not overwritten when regenerating

Or the generation gap pattern:

  • you generate abstract classes and code using skeletons of concrete classes, which you complete manually).

There is still one other way to approach this - full code generation.

It might look similar to the bad practice of coding using models, but the point is to specialize for generating certain kind of applications - web apps, embedded apps. What you generate is then basically a framework specific code, which can be often expressed and maintained using models.

Don't forget, that modeling is not just about diagrams, you can use textual DSLs as well.

To your question - UML was not originally ment for MDD (many MDD practicioners don't use UML at all...), so you can use it for OO analysis and design as you like.

When it comes to your boss and RSA, try to find out what your boss really needs and wants, then try to provide him some better tools or practices.

As mentioned in the other answer, there are many tools for documentation.

sjas
  • 18,644
  • 14
  • 87
  • 92
Gabriel Ščerbák
  • 18,240
  • 8
  • 37
  • 52
  • 1
    I can today control my code generation using a live code and model synchronization tool. I also want if I code and don't want to use UML at this stage is to be able to merge my manually typed code with the model in an incremental way and not to erase my model. What I don't want is MDD modeling then full code generation because it is stupid to have to add blocks, protected code etc....Their should a logic between code and model and not just model driven code generation and after good luck for your project !! – UML GURU Jan 30 '11 at 11:10
  • 1
    The preferred way would by in my opinion to never do model level changes in code, do them only in model and regenerate. The reason for this is that it is easier to generate code from model than to change model based on code. The only problem is than combination of generated and manually written code. Ifyou don't like protected regions really look into generation gap pattern. It can be very useful, but in Java it is not perfect because of lack of traits in the language. – Gabriel Ščerbák Jan 30 '11 at 13:55
  • 1
    You can use various design patterns to integrate the code - e.g. you can generate code using some Strategy, which would be coded manually and injected using DI. – Gabriel Ščerbák Jan 30 '11 at 13:55
0

With MDD, making changes to the design hopefully becomes cheaper: if the requirements change, in your approach you have to update the UML-based documentation, and the code. Now, if the code could be automatically generated, the changes to the code should follow automatically from the changes to the model, and you wouldn't have to do it manually (at least in those places where you don't add new stuff or need to change the business logic).

Assuming that MDD works (yeah, right ;), could you justify the double cost of maintaining the model (for documentation and design), and the code?

One argument in your favour could be that if the project isn't too big (whatever that means), that it's not worth having all the overhead.

Volker Stolz
  • 7,274
  • 1
  • 32
  • 50