my dog learned polymorphism*
The moose likes OO, Patterns, UML and Refactoring and the fly likes Chain of Responsibility Pattern Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Bookmark "Chain of Responsibility Pattern" Watch "Chain of Responsibility Pattern" New topic
Author

Chain of Responsibility Pattern

Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
In the Chain of Responsibility pattern, Is it a must condition for COR pattern that the request must flow from most specic Request Handler to Most generic Request Handler as mentioned in the book (Page no.142 pt no.1) "Java Design Pattern" By James W Cooper .

In certain cases this point is suitable. For example Java Exception Handling mechanism (Most specific exception to most general Exception).
Similary AWT Event (Button clicked). But the example given in http://www.dofactory.com/Patterns/PatternChain.aspx
is doing the process reversely. Is it a valid example? because in this case the initially request is handled by Director-Request Handler(RH), if not DirectorRH then request will be handled by his superiors Vice Presidents(VP), if VP's not then by Presidents.

Regards,
M.S.Raman
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
Originally posted by Malli Raman:
In the Chain of Responsibility pattern, Is it a must condition for COR pattern that the request must flow from most specic Request Handler to Most generic Request Handler as mentioned in the book (Page no.142 pt no.1) "Java Design Pattern" By James W Cooper .


While I don't have the Cooper book, I DO have the GoF book handy. The GoF does not indicate that it is a requirement, only that it is natural.


In certain cases this point is suitable. For example Java Exception Handling mechanism (Most specific exception to most general Exception).


This case I wouldn't really call a COR pattern. But in this case, it IS required in order for the exception handling to work properly!

But the example given in http://www.dofactory.com/Patterns/PatternChain.aspx
is doing the process reversely.


Look again. Each of the handlers in this case is an Approver, but there is no hierarchial relationship. i.e. Director is no less specific than VicePresident or President. It's like comparing a NumberFormatException to an IOException. They're both exceptions, but you might handle them differently and neither will be accepted where the other is not.

Is it a valid example? because in this case the initially request is handled by Director-Request Handler(RH), if not DirectorRH then request will be handled by his superiors Vice Presidents(VP), if VP's not then by Presidents.


Sure; The CoR pattern simply implies that the sender and receiver are decoupled and that the request is passed along a series of objects until one of them handles it. That's exactly what the example you cite does.
[ June 09, 2004: Message edited by: David Hibbs ]

"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Malli Raman
Ranch Hand

Joined: Nov 07, 2001
Posts: 312
Thanks David.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Chain of Responsibility Pattern
 
Similar Threads
UNDO operation is mandatory in Command Pattern?
Builder Design pattern
Confusion in Chain of responsibility and Decorator Pattern
What is a factory ?
design pattern