简体   繁体   English

GOF模式UML图中的相关性箭头

[英]Dependency arrows in GOF Patterns UML diagrams

It's more or less clear to me what GOF patterns are and how they behave. 对我而言,或多或少地了解了什么是GOF模式及其行为方式。
However, I feel I miss something global (in UML or patterns), as I'd draw an extra arrow or two in many GOF class diagrams if I try to repeat them from my mind. 但是,我觉得我错过了一些全局性的内容(以UML或模式表示),因为如果我尝试从脑海中重复它们,则会在许多GOF类图中绘制一两个额外的箭头。 I understand that UML diagram doesn't have to show all connections, but why not all connections are in concise pattern diagrams. 我知道UML图不必显示所有连接,但是为什么不是所有连接都在简洁的模式图中。

A couple of examples: 几个例子:

Factory Method UML diagram: 工厂方法UML图:
http://en.wikipedia.org/wiki/Factory_method_pattern http://en.wikipedia.org/wiki/Factory_method_pattern

Why no association line (plain solid arrow) from Creator to Product? 为什么从创建者到产品之间没有关联线(纯实心箭头)? There is a note for FactoryMethod: "product = FactoryMethod()". 对于FactoryMethod,有一个注释:“ product = FactoryMethod()”。 It means Creator keeps track of Product. 这意味着创作者会跟踪产品。 Why there is no connection in UML? 为什么UML中没有连接?

Command pattern UML diagram: 命令模式UML图:
http://en.wikipedia.org/wiki/Command_pattern http://en.wikipedia.org/wiki/Command_pattern

Why Invoker is orphaned? 为什么Invoker是孤立的? Client is associated with Receiver, depends on Concrete command, but it needs to pass the command to Invoker. 客户端与Receiver相关联,取决于具体命令,但是它需要将该命令传递给Invoker。 Why no connection between Client and Invoker? 为什么客户端和调用者之间没有连接?

Thanks for your answers. 感谢您的回答。

You're confusing structure with behavior. 您将结构与行为混淆了。

An association implies a structural dependency, typically a "has a" relationship. 关联意味着结构上的依赖关系,通常是“具有”关系。 A has a B. However, this is more like "Bill has a finger" rather than "Bill has a wallet". A有一个B。但是,这更像是“比尔有手指”而不是“比尔有钱包”。 Bill may sometimes have a wallet, but that is not something structurally defining bill as a Human Being. 比尔有时可能有一个钱包,但这并不是从结构上将比尔定义为人类的东西。

Does Creator have a product? 创作者有产品吗? No, not structurally. 不,不是结构上的。 Neither does Concreate Creator. Concreate Creator也没有。 They instantiate a Product and then return it (I'm not sure a Realizes association is appropriate there, never thought of returning something as realizing it). 他们实例化一个Product,然后返回它(我不确定Realizes关联在这里是否合适,从来没有想过要返回实现的东西)。 They do not keep track of the Product in most cases. 在大多数情况下,他们不会跟踪产品。

Consider a class Chef, that creates a Meal object. 考虑一个厨师类,它创建一个Meal对象。 Does the Chef keep track of the meal after he's returned it to Customer class? 厨师将餐点归还给客户后,是否保持跟踪? No, he's on to the next meal. 不,他要吃下一顿饭。 Therefore, no association between Chef and Meal. 因此,Chef和Meal之间没有关联。

Yes, it's true that a Chef owns a meal temporarily as he's making it, but the meal is not a structural part of the chef. 是的,的确,厨师在做饭时会暂时拥有一顿饭,但是这不是厨师的结构性部分。 He only constructs the Meal and hands it of to the consumer. 他只构造膳食并将其交给消费者。 Object diagrams show structure of the objects, not what the methods of the objects do. 对象图显示对象的结构,而不是对象的方法。 That's a different kind of diagram, such as an Activity diagram. 那是另一种图,例如活动图。

As for your Command pattern question, Invoker depends on the Interface, not the Command object itself. 至于您的命令模式问题,Invoker取决于接口,而不是命令对象本身。 Because Invoker depends only on an interface, you can pass it any kind of object that implements the interface. 因为Invoker仅依赖于接口,所以您可以将实现该接口的任何类型的对象传递给它。 It doesn't have to be a command even, so long as it pretends to be one. 只要它假装成一个命令,它甚至不必是命令。

Invoker doesn't know what it's invoking, so no dependency and no association. 调用者不知道调用的是什么,因此没有依赖性也没有关联。 As an example, consider that someone blindfolds you, and asks you to identify an object they give you. 例如,假设某人蒙住了您,并要求您识别他们给您的物体。 You might be able to tell what many objects are, but some you might not. 您也许能够分辨出多少个对象,但是您可能不知道。 For example, you might not know the difference between bread dough and playdough, or a large orange and a small grapefruit. 例如,您可能不知道面包面团和面团,大橘子和小柚子之间的区别。 For all intents and purposes, a large orange and a small grapefruit implement the same tactile interface, but they produce different results when you execute them (eat them). 出于所有目的和目的,一个大橙子和一个小柚子实现了相同的触觉界面,但是当您执行它们(吃掉它们)时,它们会产生不同的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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