File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chain of Responsibility Pattern

 
Malli Raman
Ranch Hand
Posts: 312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Malli Raman
Ranch Hand
Posts: 312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic