“使用”和“使用”有什么区别?和“取决于”?

发布于 2024-11-18 02:53:37 字数 322 浏览 3 评论 0原文

在这个依赖注入初学者指南中我注意到UML 图区分“使用”和“依赖于”。

由于两者都需要在类中“使用”或“依赖”某种形式的引用,我想知道:两者之间真正的区别是什么?

In this beginners guide to Dependency Injection I noticed that the UML diagram distinguishes between "uses" and "depends upon".

Since both require some form of a reference in the class that "uses" or "depends upon", I wonder: What is really the difference between the two?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沧笙踏歌 2024-11-25 02:53:37

查看取自 IBM Rational Software Architect 文档

“取决于”的含义如下:

依赖关系表示
更改为一个模型元素(
供应商或独立模型元素)
可能会导致另一个模型的变化
元素(客户端或依赖模型
元素)。供应商模型元素
是独立的,因为改变
客户端不影响它。客户
模型元素取决于供应商
因为更换了供应商
影响客户端。

“使用”的含义如下:

使用关系是一种依赖关系
关系,其中一个模型
元素需要存在
另一个模型元素(或一组模型
要素)以全面实施
或操作。模型元素
需要另一个模型的存在
元素是客户端,模型是
需要存在的元素是
供应商。虽然是一个用法
关系表明一种持续的
的要求,也表明
两个模型之间的联系
元素并不总是有意义或
存在。

正如我所读到的,“用法”是一种不太严格的“依赖关系”。

Check out the blockquotes about relationship types taken from IBM Rational Software Architect documentation.

"depends upon" means the following:

A dependency relationship indicates
that changes to one model element (the
supplier or independent model element)
can cause changes in another model
element (the client or dependent model
element). The supplier model element
is independent because a change in the
client does not affect it. The client
model element depends on the supplier
because a change to the supplier
affects the client.

"uses" means the following:

A usage relationship is a dependency
relationship in which one model
element requires the presence of
another model element (or set of model
elements) for its full implementation
or operation. The model element that
requires the presence of another model
element is the client, and the model
element whose presence is required is
the supplier. Although a usage
relationship indicates an ongoing
requirement, it also indicates that
the connection between the two model
elements is not always meaningful or
present.

As I read it "usage" is a less strict "dependency".

书间行客 2024-11-25 02:53:37

“使用”是一个类引用另一个类的某些操作的地方。

“取决于”是指 A 类在其实现中使用另一个 B 类(例如作为方法的参数)。在这种情况下,更改 B 类可能需要更改 A 类。

请注意,我已经说过“类”,但它同样适用于“接口”。

维基百科对此有一篇很好的文章: http://en.wikipedia.org/wiki/ Dependency_%28UML%29

因此,例如,您可以在类驱动程序和接口 IVehicle 之间建立使用关系,该关系公开一个名为 Drive() 的方法。对 Drive 实现的更改不需要对 Driver 进行任何更改,因此您说 Driver 使用 IVehicle。

然而,类驱动程序对类手有依赖关系,因为驱动程序有两个属性:手左手和手右手。如果这些的实现发生变化,则需要考虑驱动程序是否需要相应更新。

"Uses" is where one Class refers to another Class for some of it's operations.

"Depends on" is where a Class A uses another Class B within it's implementation (e.g. as a parameter to a method). In this case changing Class B may necessitate a change to class A.

Note I've said Class, but it applies equally to Interfaces.

Wikipedia has a good article on this: http://en.wikipedia.org/wiki/Dependency_%28UML%29

So for example you could have a Uses relationship between a Class Driver and an Interface IVehicle which exposes a method called Drive(). Changes to the implementation of Drive do not require any changes to Driver, so you say Driver uses IVehicle.

However Class Driver has a Dependency on Class Hand, since Driver has two properties: Hand LeftHand and Hand RightHand. If the implementation of these changed, one would need to consider if Driver needed updating accordingly.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文