I browsed the web but I couldn't find an answer to my question...
Lets 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). Is it possible to use CoR pattern for this problem?
To explain it better - I have a list that has to pass through several sets of rules. If it passes the 1st rule, list stays the same. Then it goes on to the 2nd rule, and 2nd rule changes a list. The changed list goes to the 3rd rule, it passes and the altered list is saved.
Hm, I don't see any counter argument not to do that.
You can simply declare your Processor
or however you call that:
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 were asking ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With