将 UML 嵌入到 Java 代码中最常见的方法是什么?
我正在尝试将 UML 序列和类图添加到我的 Java 代码中,以解释其内部结构和设计概念。我希望这些图表在 JavaDoc 块中指定,然后转换为附加到 API HTML 的 PNG/GIF 图像。
我可以使用什么工具来自动化此过程(我使用的是 Maven 3)?
I'm trying to add UML sequence and class diagrams to my Java code, in order to explain its internals and design concepts. I would like these diagrams to be specified in JavaDoc blocks and then converted into PNG/GIF images attached to API HTML.
What tool I can use for the automation of this process (I'm using Maven 3)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Javadoc 中的 UML 图:
本文展示了在 Javadoc 中包含 UML 图并根据源代码存储库中的每次更改保持更新是多么容易和简单。
UML Diagrams within Javadocs:
This article shows how easy and simple it is to include UML diagrams within your Javadoc and also keep them updated with every change in the source code repository.
我编写了一个 ant/maven 插件,它使用 javadoc 来绘制动画/图像。
I wrote a ant/maven plugin that uses javadoc to paint animations/images.
我认为应该更新模型,而不仅仅是将图表转换为 PNG/GIF 等......
自动生成图表没有实际价值。
例如,在一个自动生成的图表中显示一个巨大的类及其所有方法(例如有时超过 100 个)有什么好处?你可能会得到巨大的图表,但不明白为什么要编写此代码,并且无法理解架构等...你只是看到代码的图形视图,这不是 UML 的目标!
我在项目中为我的代码所做的是使用以下功能:
The show hide javadoc 在我的 UML 类图中显示 java doc
I也可以使用相反的方法来获得序列图。
我最欣赏的是能够在代码中实时导航,然后提取我的模型并仅在模型中导航。我可以对任何我想要的东西进行建模,并在将其交给开发团队之前尝试新的架构。
我认为 JavaDoc 中包含的自动图表生成不是应该做的。如果您只需手动花费 5 分钟,您就可以使用所有更改来更新现有模型。您将能够创建自定义 UML 视图,并在其中添加注释。拥有视图将为团队提供更好的信息,同时节省时间并提高代码质量。
您可以做的是为每个开发人员提供一个 UML 查看器以及 JavaDoc 中的一个链接。开发人员只需单击链接即可打开自动更新的图表。不再需要痛苦的图像导出和错误更新,因为图像一旦创建就无法更改。您仍然可以创建新图像,但您会丢失注释、演示文稿等......并且只能获得一个静态的巨大图表,包括所有方法、属性等......无法检测高级关联和依赖关系。只有继承检测才是正确的!!
您的UML模型可以与maven和SVN一起使用,真正为您的项目和建模带来真正的价值,这是图像导出无法实现的。在我看来,您尝试使用 UML 图只是为了将 UML 添加到您的项目中,但添加没有视图、注释等的严重反向项目的图像导出...不是 UML,在 Java 项目中没有任何价值
I think that the model should be updated and not just diagrams converted to PNG/GIF etc....
Producing automatic diagram has no real value.
What is the interest of for example showing a huge class and all its methods (e.g. sometimes over 100) in a single automatically generated diagram ? You could get huge diagram and not understand why this code has been written and could not understand the architecture etc...You just see a graphical view of your code which is not the goal of UML !!
What I do in my projects for my code is to use following features:
The show hide javadoc display java doc in my UML class diagram
I also use the reverse of a method in order to get a sequence diagram.
What I appreciate the most is to be able to live navigation in the code and then extract my model and only navigate in the model. I can model whatever I want and try new architectures before giving it the developer team.
I think that automatic diagram generation to be included in the JavaDoc is not what should be done. If you only spend 5 minutes manually, you would be able to update your existing model with all changes. You would be able to create customize UML views in which you would be able to add comments. Having views will provide better information to the team while saving time and adding quality to the code.
What you can do is to provide an UML viewer for each developer and a link in your JavaDoc. The developer will only need to click on the link and would be able to open the diagram which would be automatically update. No more painful image export, wrong update because once the image has been created it is impossible to change it. You can still create new images but you loose your comments, presentation etc..... and only get a static huge diagram including all methods, attributes etc...not being able to detect advanced association and dependencies. Only inheritances detection is correct !!
You UML model could be used with maven and SVN and really bring real value to your project and modelling which can not be achieved by image export. It seems to me you try to use UML diagrams just in order to add UML to your project but adding image export of a badly reverse project without views, comments etc...is not UML and has no value in a Java project