[英]In UML class diagram, should I draw a dependency from class A to B, if B is used by interface which is used by class A?
If I have a class A that uses some interface I, and that interface returns class B, should I draw a dependency from A to B on UML class diagram?如果我有一个使用某些接口 I 的 class A,并且该接口返回 class B,我应该在 UML class 图上绘制从 A 到 B 的依赖关系吗?
You describe a class A
which uses an interface I
which uses a class B
.您描述了一个 class A
,它使用一个接口I
,它使用一个 class B
This could look somewhat like:这看起来有点像:
Should you show a dependency of A to B?你应该表现出 A 对 B 的依赖性吗?
Now a definition:现在一个定义:
A Usage is a Dependency in which one NamedElement requires another NamedElement (or set of NamedElements) for its full implementation or operation. Usage 是一种依赖关系,其中一个 NamedElement 需要另一个 NamedElement(或一组 NamedElements)来实现其完整实现或操作。 The Usage does not specify how the client uses the supplier other than the fact that the supplier is used by the definition or implementation of the client.除了客户端的定义或实现使用供应商这一事实外,该用法并未指定客户端如何使用供应商。
It is not required by UML, nor by your design, but if you want to document the implementation, you may have a second thought at dependencies. UML 和您的设计都不需要它,但如果您想记录实现,您可能会重新考虑依赖性。 Some languages such as C++ may require for compiling A, to have the definition of I which would require to include the definition of B. So to compile A you may need to know B. If you think it would help you to stay aware of such dependencies, you could show it.某些语言(例如 C++)可能需要编译 A,以包含 I 的定义,这需要包含 B 的定义。因此,要编译 A,您可能需要了解 B。如果您认为这有助于您了解此类信息依赖关系,你可以展示它。 It is not wrong, but personally, I advise to show only direct dependencies, because you can easily deduce the transitive ones, without cluttering the diagram with a lot of extra arrows.这没有错,但就我个人而言,我建议只显示直接依赖关系,因为您可以轻松推断出传递依赖关系,而不会用大量额外的箭头使图表混乱。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.