Does anyone know if this template has a name? I try to use it sufficiently.
This is basically a behavioral pattern that allows you to provide a method with enumerated classes that implement the interface, and it runs all of them. Here is a C # example:
interface IInputValidator { bool IsValid(int input); } class GreaterThanZeroValidator : IInputValidator { public bool IsValid(int input) { return input > 0; } } class LessThanOneThousandValidator : IInputValidator { public bool IsValid(int input) { return input < 1000; } }
then a method that uses them:
public void ValidateInput(int input, IEnumerable<IInputValidator> validators) { bool allValid = true; foreach(var validator in validators) { if(!validator.IsValid(input)) allValid = false; } if(!allValid) throw new ArgumentException(); }
So, for me, this looks like a strategy template, but with a few strategies that everyone gets the opportunity to process input, while a regular Strat template accepts only 1 strategy.
It is also a bit like a chain of responsibility, except that in a regular CoR, only the iterators are deep enough to find one that can handle the input, and each responsibility has a link to the next responsibility (for example, a linked list), whereas in In my example, I pass them all together.
I just want to call it. Thanks for any help!
source share