英文:
Do we need to add interface Runnable in our UML class diagram?
问题
我已经用套接字编程创建了一个简单的FlappyBird克隆游戏,现在我正在做UML图。我的类实现了Runnable接口。
像这样:
static class Flappy implements Runnable{....}
和:
public class Client extends Application implements Runnable{.....}
英文:
I have created a simple FlappyBird clone game with socket programming and now I am doing the UML diagram.
My classes implements Runnable
Like:
static class Flappy implements Runnable{....}
and:
public class Client extends Application implements Runnable{.....}
答案1
得分: 3
虽然用户7之前接受的回答本身是正确的,但也存在一些"情况有所不同"。如果您为机器(代码生成器)或编码人员创建UML图,您将不得不添加它以使其完整。如果是为了普通(人类)理解,您可以省略这些细节。
顺便提一下:您的箭头是错误的。那些是扩展点(仅用于配置文件定义),不是实现关系。实现关系有一个开放的三角形和一个虚线。
英文:
Though the (formerly) accepted answer by user7 is right per se, there's also a "it depends". If you create your UML for a machine (a code generator) or a coding monkey you will have to add it in order to make it complete. If it's for a common (human) understanding you can omit those details.
As a side note: your arrows are wrong. Those are extensions (used only in profile definitions), not realizations. A realization has an open triangle and a dashed line.
答案2
得分: 3
UML是方法论无关的。所以,一切都取决于你的类图的目的:
- 如果它是分析或领域模型,则
Runnable
不相关(正如其他答案所指出的) - 如果它是设计模型,即解释解决方案如何工作的模型,那么
Runnable
对于你的设计有多相关就取决于你:- 如果你的解决方案中没有任何部分需要一个
Runnable
,那么你不需要显示它。 - 如果一个类期望使用
Runnable
或者在更大范围的组件设计中期望该类提供这个接口,那么你应该显示它。
- 如果你的解决方案中没有任何部分需要一个
- 如果它是实现模型,即旨在精确记录解决方案如何实现的模型,那么应该记录
Runnable
。请注意,使用这种详细的实现模型对学校工作来说是不错的选择,但对于现实世界的项目来说并不是一个有趣的选项,因为它很难维护,并且在某种程度上与代码有些冗余,除非你有可以为你生成图表的逆向工程工具。
如果你决定显示这种关系,你将需要重新调整你的图形布局:
-
箭头头必须替换为泛化的空白三角形。纯箭头头是模糊的,可能会误导读者认为它是一个可导航的关联(原则上用开放的箭头头表示,但仍然是箭头头)
-
但由于
Runnable
是一个接口,而你的类是implement
它而不是extend
它,所以你应该使用虚线来表示它是接口的实现(这是一种依赖关系,具有与继承/泛化略有不同的含义)。
英文:
UML is methodology agnostic. So, it all depends on the purpose of your class diagram:
- If it is an analysis or a domain model, the
Runnable
is not relevant (as the other answer rightly pointed out) - If it is a design model, i.e. a model that explains how your solution works, it depends how relevant
Runnable
is for your design:- if nothing in your solution requires a
Runnable
, you don’t need to show it. - if one class expects to use a
Runnable
or if the class is expected to provide this interface in the larger view of the component design, then you should show it.
- if nothing in your solution requires a
- If it is an implementation model, i.e a model that aims to document precisely how your solution is implemented, the
Runnable
should be documented. Be aware that the use of such detailed implementation models is good for school-work but is not an interesting option for real world projects because it’s difficult to maintain and somewhat redundant with the code, unless you have reverse-engineering tools that can generate the diagram for you.
If you decide to show the relation, you’ll have to rework your graphical layout:
-
the arrow head must be replaced with the blank triangle of generalization. A plain arrow head is ambiguous and could mislead the reader to think that it’s a navigable association (in principle shown with an open arrow head, but an arrow head nevertheless)
-
but since
Runnable
is an interface, and your classesimplement
it and do notextend
it, you should use a dashed line to show that it’s the realization of an interface (which is a dependency, with a slightly different meaning that the inheritance/generalization).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论