• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chain of responsibilty

 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any example in java?
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The event of filtering e-mail is an example of Chain of Responsibiity.
Therefore for instance, if the e-mail is spam e-mail it does not get forwarded to the recipients e-mail box.
Think of it as a Client not sending the request(e-mail) directly to the recipient but to many objects in between until one is found to handle it.
Eventually the right mail gets to the recipient's box or recipients' e-mail box in the case of group or bulk mail.
The aim of the Chain of Responsibility pattern is to decouple the sender and reciever of a request.So you shouldn't have code that sends a request to a particular reciever directly IMHO. We could try writing an example in Java and see how far we get.

Hope this helps.
regards
[ November 09, 2003: Message edited by: HS Thomas ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The AWT container hierarchy is an implementation of chain of responsibility. When an event is posted to a button or other GUI component, it either handles the event or posts it to its container.
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another example:
When a user enters a date, a chain of parsers then try to decode the date.
regards.
[ November 11, 2003: Message edited by: HS Thomas ]
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlet Filters (since 2.3 I guess) and I think even Apache Axis handlers follow the pattern.
 
HS Thomas
Ranch Hand
Posts: 3404
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Now this code can be refactored to use Chain of Responsibility. Where do I start ? I'll re-visit this in a little while to flesh it out a little. I'm trying to get Poseidon to work.
regards
[ November 11, 2003: Message edited by: HS Thomas ]
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any requirement that a single object has to handle the reuest or many objects in the chain can handle processing so that each object can produce some output of value to the client.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The original chain of responsibility pattern states that only one member in the chain handles the "event". If the event is handled by 0..n members, it's no longer a chain of responsibility -- no one is responsible anymore, but everyone has an option to do something with the event.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic