简体   繁体   English

对于责任链模式,哪个UML图是正确的?

[英]Which UML diagram is correct for Chain of responsibility pattern?

I am trying to draw UML diagram for Chain of responsibility pattern. 我正在尝试为责任链模式绘制UML图。 I am referring the sites http://www.vincehuston.org/dp/chain.html and 我指的是网站http://www.vincehuston.org/dp/chain.html

http://www.dofactory.com/Patterns/PatternChain.aspx http://www.dofactory.com/Patterns/PatternChain.aspx

In Vincehuston diagram, there is a self loop at base class, because Base class needs to have a pointer to next handler object. 在Vincehuston图中,基类存在一个自循环,因为基类需要具有指向下一个处理程序对象的指针。

In dofactory diagram, there is aggregation of base class in Derived class. 在工厂图中,派生类中有基类的集合。

Could you pls tell me which one is correct ? 您能告诉我哪一个是正确的吗? DoFactory mostly explaining based on C#, does it make any difference ? DoFactory主要基于C#进行解释,这有什么区别吗?

The only difference I see between the two explanations is where the pointer to the next handler is (base handler class or concrete implementation) which should be represented on the base class as it will be inherited in every instance. 我看到的两种解释之间的唯一区别是,指向下一个处理程序的指针的位置(基本处理程序类或具体实现)应该在基类上表示,因为它将在每个实例中继承。

So from my point of view vincehuston representation is more accurate. 因此,从我的角度来看,文斯休斯顿的代表制更为准确。

If you look at the actual implementation in dotfactory you'll see that, despite the UML representation it puts the successor in the base class anyway. 如果您查看dotfactory中的实际实现,您会发现,尽管使用UML表示,但无论如何它将后继者放置在基类中。

Edit: The implementation differs in the way the successor is invoked by providing and instance to the successor or a base method for invoking the successor. 编辑:实现方式的不同之处在于,通过向后继者提供实例并为后继者提供实例来调用后继者,也可以通过基本方法调用后继者。 In both cases the method or member is inherited from the base class so the aggregation is wrong, you don't define an aggregation when you use inherited members or methods. 在这两种情况下,方法或成员都是从基类继承的,因此聚合是错误的,在使用继承的成员或方法时,您无需定义聚合。

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

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