简体   繁体   English

在 UML class 图中,如果 B 被 class A 使用的接口使用,我是否应该绘制从 class A 到 B 的依赖关系?

[英]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 的依赖性吗?

  • First of all, you are not obliged to show all the potential dependencies in your model, but only those that you think are releveant to understand the problem.首先,您没有义务在您的 model 中显示所有潜在的依赖关系,而只显示您认为与理解问题相关的那些。
  • The usage dependency is not necessarily transitive: A can use I without using B, and even without knowing B. Your narrative does not establish that there is a direct usage dependency between A and B, so you should not show it (unless you know there is a direct dependency).使用依赖不一定是传递性的:A 可以在不使用 B 的情况下使用 I,甚至不知道 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM