Responsibility chain - forward the request through all chains

I browsed the Internet but could not find the answer to my question ...

Let's say I have 3 chains. I want the request to pass all 3 chains (it doesn't matter if the chain can handle the request or not). Can I use a CoR pattern for this problem?

To explain this better, I have a list that must go through several sets of rules. If he passes the 1st rule, the list will remain the same. He then moves on to the second rule, and the second rule modifies the list. The modified list proceeds to the third rule, it passes, and the modified list is saved. Chains

+5
source share
1 answer

Hm, I do not see the counter argument, so as not to do this.

You can simply declare your Processor or, as you call it:

 abstract class Processor { private Processor successor; public void setSuccessor(Processor successor) { this.successor = successor; } public List process(List input) { List processed = this.internalProcess(input); if (successor != null) { return successor.process(processed); } return processed; } protected abstract List internalProcess(List input); } 

and then you can define, for example:

 public class ProcessorNoProcess extends Processor { @Override protected List internalProcess(List input) { // do nothing return input; } } 

Is that what you asked?

+1
source

Source: https://habr.com/ru/post/1237134/


All Articles