问题
I am trying to design my applications know before writing some code. I've created class diagram of all classes am going to use and then generated code from them using Astah.
The problem occurs when I want to change a method of some class or add a new one. I should do this twice: once in the class diagram and once in the source code. Several evolutions of this kind being proceeded, my class diagram becomes easily out of date.
Is there some approach to avoid this? Can I update already existing code from activity diagram?
Thank you in advance
回答1:
For answering your question, it seems to me pertinent to consider the way UML is used.
In UML distilled, Martin Fowler considers three ways of using UML:
- Sketch
- Blueprint
- Executable UML
1. Sketch
The sketch use of UML is convenient for refactoring programs, a practice Fowler is seriously interested in. In general this is appropriate to have a synthetic perception of an existing program.
2. Blueprint
Blueprint is in a way the academic use of the language. The main problem is in software evolution: the models have to be revisited with the code not to become legacy.
3. Executable UML
Executable UML is a kind of extreme practice of the language in which it becomes the main way of expression for a program. In that context, the program is usually generated from the initial UML model which contains all the software informations. The source code is only a transition form of the software. The software evolves with the model, code generated again. This is possible only with a complete UML modeling of the software. In a few words, this is a radical use of UML.
I think the distinction between these three ways of using UML is a pertinent consideration about the general use of UML.
UML as an interface for source code modification
However I understand what you are looking for: there should be another (fourth) way of using UML, as an interface for source code modification. A few solutions exist but none is really convenient, here are the initiatives I identified :
- Green UML is an Eclipse plug-in by the University of Buffalo which uses its own class diagram editor
- Code Canvas was a research project by Microsoft, not UML but interesting, an article is available in the ACM communications
- BlueJ is a very light IDE including a class diagram editor modifying the source code
- Coffea UML is a personal project
A few words here about Coffea. Its purpose was to link the Eclipse JDT refactoring functions to the Eclipse UML2Tools diagram editors. It worked correctly with the class diagram editor. My ambition was to extend it to the activity diagram. Unfortunately the UML2Tools have become legacy since then. Coffea is not dead but almost. I have separated the core UML2 functions from the UML2Tools editors. My intentions are detailed in the project site. However I work on it on my spare time and I have other occupations.
UML can be used as an interface for source code modification if and only if the modification is only on one aspect (e.g. behavioral or structural). It would be quite impossible to have a comprehensive edition of the software outside of the scope of Executable UML. The supposed editor for such a purpose would be a combination of multiple diagrams, what would be very complicated. Such an editor should be close to the sketch mode described by Fowler.
Conclusion
Unfortunately, I think that UML as an interface for source code modification is currently something theoretic. A main challenge would be to integrate the modification with an initial UML model (your case). Given the variety of UML tools, I think Fowler's uses of UML are the only serious solutions. It seems you can only use Astah for Executable UML. I am not even sure the tool provides all the features to do so.
来源:https://stackoverflow.com/questions/27869353/keep-class-diagram-and-code-synchronized