0
Is this an example of chain of responsibility
Hi Refer code below: Is this an example of chain of responsibility ? If not, why ? If yes, whats the use of this design pattern in real life ? https://code.sololearn.com/c3mpuAd44hMr/?ref=app
4 odpowiedzi
+ 1
Its not chain of responsability pattern.. See here https://refactoring.guru/design-patterns/chain-of-responsibility/ (the entite site is very good on patterns)
+ 1
Thanks KrOW
Deep down i had doubt that it is not as request is excuted partially and then passed to next handler
What I am confused is about true use case of this pattern.
As most of the sites suggest call center as example, i have doubt about this pattern with factory
Say for example, there is factory to create an object of loan department executive, credit card department, fraud department etc. Whatever request is there by user, that object should be returned and all these objects have method called resolvequery
Why to choose chain of responsibility here in this case ? I think i am missing base use of this pattern.
Thanks again for your time and help
+ 1
factory is a creational pattern while chain of responsability is a behavioural one and you can mix the patterns for obtain specific design.
Nothing prevent your to use the chain of responsability pattern for handle any department process and the factory for create appropriate type for handle that process.
0
Sorry but I didnt get you. What is purpose of using both at same time in this example?
Either create required object using factory and call method to fulfil the task or pass request to any object and chain of responsibility decides internally which object will solve the task.
What is the one example which only chain of responsibility solves very well and others can't