UML:有人能为我解释一下工厂方法图吗?

发布于 2024-07-25 01:06:25 字数 405 浏览 9 评论 0原文

我不知道从 ConcreteCreator 到 ConcreteProduct 的断箭头意味着什么。 我在互联网上搜索,我想出了“依赖”。 有人可以用外行的术语解释依赖性吗? 谢谢!

替代文本

http://www.dofactory.com/Patterns/PatternFactory 抓取的图像.aspx

i dont have an idea what the broken arrow from the ConcreteCreator to the ConcreteProduct means. i searched in the internet and i came up with "Dependency". can someone explain the dependency in layman's terms? thanks!

alt text

image grabbed from http://www.dofactory.com/Patterns/PatternFactory.aspx

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

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

发布评论

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

评论(4

半边脸i 2024-08-01 01:06:25

正如您正确指出的那样,虚线表示 ConcreteCreator(作为依赖元素或客户端元素)和 ConcreteProduct(作为独立元素或供应商元素)之间的依赖关系。

在这种特定情况下,该行指示 ConcreteCreator 负责创建 ConcreteProduct 的实例。 通过将“create”构造型附加到依赖项可以使这一点变得更加清晰。

As you rightly state, the dashed line indicates a dependency relationship between ConcreteCreator (as the dependent, or client, element) and ConcreteProduct (as the independent, or supplier,element).

In this specific case, the line indicates that ConcreteCreator is responsible for creating instance(s) of ConcreteProduct. This could have been made more clear by attaching the 'create' stereotype to the dependency.

一页 2024-08-01 01:06:25

虚线/空箭头表示依赖关系,这意味着 ConcreteCreator 以某种方式“使用”ConcreteProduct。 箭头本身并没有定义该依赖关系的性质,只是定义了依赖关系的存在,并且 ConcreteProduct 实际上并不是 ConcreteCreator 的成员。

所提供的注释(即“返回新的ConcreteProduct”)意味着ConcreteCreator 将实例化(或创建)ConcreteProduct 类型的对象,这对于工厂来说是很自然的。 传统上,在 UML 中,您可以通过编写“<>”来阐明这种关系。 在虚线箭头上方。 UML 将这些注释称为“刻板印象”。

有关详细信息,请参阅 Allen Holub 的 UML 快速参考。 您可以看到他有一个非常相似的示例,其中“用户”创建“资源”。

The broken line/empty arrow head denotes a dependency, meaning that ConcreteCreator "uses" ConcreteProduct in some way. The arrow itself doesn't define the nature of that dependency, only that a dependency exists and that ConcreteProduct is not actually a member of the ConcreteCreator.

The provided note (i.e., "return new ConcreteProduct") implies that ConcreteCreator will be instantiating (or creating) objects of type ConcreteProduct, which is natural for a factory. Traditionally in UML, you could clarify this relationship by writing "<<creates>>" over the dashed arrow. UML calls these notes "stereotypes."

See Allen Holub's UML Quick Reference for more information. You can see he has a very similar example where "Users" create "Resources".

别在捏我脸啦 2024-08-01 01:06:25

我认为这意味着 ConcreteCreator 必须知道 ConcreteProduct 是什么才能创建它,因此那里存在显式依赖关系。 工厂方法创建一个 Product,但该方法的 ConcreteCreator 重写必须返回一个 ConcreteProduct。

I think it means that a ConcreteCreator has to know what a ConcreteProduct is to create it, so there's an explicit dependency there. The factory method creates a Product, but the ConcreteCreator override of that method has to return a ConcreteProduct.

只有一腔孤勇 2024-08-01 01:06:25

这不仅仅是工厂方法——这看起来更像是抽象工厂模式。 Creator 的特定具体派生类将创建派生 Product 类的相应实例。

This isn't just the Factory Method - this looks more like the Abstract Factory Pattern. A specific concrete derived class of Creator will create a corresponding instance of a derived Product class.

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