I would like to share one usage of chain of responsibility pattern in my application.
Requirement is to route the message to proper backend. Input is payment instruction data. This is about determing based on type of instruction where exactly we have route message for further processing.
For this requirement i could have used simple configuration and based on some parameter i could have decided which backend handler i will delegate to. But some times this logic is complex and dificult to configure. Consider for some group of message types deciding factors may be different than other group. Morever you dont know change in logic and support for new backends.
This was guiding factor in going for chain of responsibility pattern. Here i kept chaining configuration in xml and commons api chaining support executed the chain.
Member of chain are dedicated to respective backends. Which receives same context information from chain executer and decides whether they are able to accept the message or needs to route to next member of the chain.
I can even use one chain member for more than one related backend.
Also having chaining configuration it is easier to modify chain flow.
Requirement is to route the message to proper backend. Input is payment instruction data. This is about determing based on type of instruction where exactly we have route message for further processing.
For this requirement i could have used simple configuration and based on some parameter i could have decided which backend handler i will delegate to. But some times this logic is complex and dificult to configure. Consider for some group of message types deciding factors may be different than other group. Morever you dont know change in logic and support for new backends.
This was guiding factor in going for chain of responsibility pattern. Here i kept chaining configuration in xml and commons api chaining support executed the chain.
Member of chain are dedicated to respective backends. Which receives same context information from chain executer and decides whether they are able to accept the message or needs to route to next member of the chain.
I can even use one chain member for more than one related backend.
Also having chaining configuration it is easier to modify chain flow.
No comments:
Post a Comment