I am in the design phase of a project which needs to perform certain validations on a given object. The validations can be grouped into 5 distinct groups. Each individual category of validator can have multiple versions differing slightly in their implementations.
public interface Validator {
boolean validate(Object o);
}
public abstract CostValidator implements Validator {
//common logic related to cost validator
}
public class CostValidator1 extends CostValidator {
boolean validate(Object o) {
//implementation 1
}
public class CostValidator2 extends CostValidator {
boolean validator(Object o) {
//implementation 2
}
Based on the business group of the object, either CostValidator1 or CostValidator2 needs to be executed.
For each business group, I plan on maintaining a list of such validators in a configuration system i.e:
BusinessGroupA {
validators = [CostValidator1, SomeOtherValidator2...]
}
BusinessGroupB {
validators = [CostValidator2, AnotherValidator99...]
}
The processing flow will fetch the list of validators from the configuration based on the business group and execute the validations in each of the validators thus contained.
Are there any flaws with this approach? Or is there any better way to address the use-case I described?
Aucun commentaire:
Enregistrer un commentaire