I have design issue. I want have separate class for every validation. Also I want have one class that call all this validations. Idea is that if I need new validation, than I just add new validation class and everything works. I don't need to change anything else, just add new class. Something like this:
public interface IValidate{
bool Validate();
}
public class Validator1 : IValidate{
public bool Validate(){
//Do validation 1
}
}
public class Validator2 : IValidate{
public bool Validate(){
//Do validation 2
}
}
//...
public class ValidatorN : IValidate{
public bool Validate(){
//Do validation N
}
}
//...................................
public interface IValAll{
bool Validate_All();
}
public class ValidateAll : IValAll{
public bool Validate_All(){
//Call all validators that implements IValidate interface
//Do validation 1,2...N
//If all validations return true, than this function return true.
//Else return false.
}
}
I don't know if this is best approach, but you get and idea what I want. Problem is that I don't know how to implement this Validate_All() method. How to get all class-es that implement same interface and do validation in one loop? Idea is to inject this IValAll interface and do all validation with one call. Thanks for help and advice.
Aucun commentaire:
Enregistrer un commentaire