Which UML diagram is correct for Chain of responsibility pattern?
I am trying to draw UML diagram for Chain of responsibility pattern. I am referring the sites http://www.vincehuston.org/dp/chain.html and
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 han开发者_StackOverflow社区dler object.
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 ?
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.
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.
精彩评论