I'm new to programming. I have a list of objects that I want to validate (not short circuit, but run a list of validation rules by each one).
Initially I had a huge if/else statement but it didn't look very pretty. I think something like this would be better:
foreach (object: objects) {
foreach (rule: validationRules) {
try {
rule.validate(object)
} catch {
// Write to log
// Increment counter for rule
}
}
}
I just don't know how to go about creating the validation rules. I'd like to use Java 8 predicates because I hear that's what I should be using, but I'm not sure how to go about doing it. I think I might create an interface with the rules and then an implementation with each rule defined and also the list of rules. Does this sound like a good way to go about solving this problem?
Thanks!