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 ]
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.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: May 15, 2002
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 ]
Servlet Filters (since 2.3 I guess) and I think even Apache Axis handlers follow the pattern.
Joined: May 15, 2002
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 ]
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.