I am implementing a chain of responsibility pattern.
I have different policies that can be combined in a list and I have a Processor that processes the list of policies. Each policy can process the CustomInput and can choose if the rest of the policies should be processed too.
interface Policy {
public boolean process(CustomInput input);
}
interface Processor {
public void process(List<Policy> policies, CustomInput input)
}
I was going to implement the Processor looping over the list of policies and checking the boolean result of each to know whether to continue with the rest of policies.
My colleague suggested to pass the next Policy to each Policy and let them call (or not) the next one (like FilterChain does for example).
My question is the following:
Is there any benefits I don't see in the second solution (passing the next policy to the currently processing one) over looping over each policy and checking it's result?