Reputation: 614
I have a hierarchy of classes for validation and i'm at a point that i'd like to refactor (if possible and useful) leaving the code decoupled.
public class DefaultValidation : ValidationList
{
public DefaultValidation(Cutomer customer, Dto dto)
{
DefaultRepository repository = new DefaultRepository();
EntityBook entityBook = (EntityBook)repository.GetBookById(dto.IdBook);
this.Add(new BookMustBeValidValidation(entityBook));
EntityVideo entityVideo = (EntityVideo)repository.GetVideoById(dto.IdVideo);
this.Add(new VideoValidation(entityTask));
this.Add(new OtherNecessaryValidation(dto.OtherProperty));
}
}
This class is a concrete for validation. I add all the rules in a list so i can add various kind of validation in form of classes.
(I used this method that seemed interesting)
The need of a refactory comes when i add another similar class:
public class SpecialValidation : ValidationList
{
public SpecialValidation(Cliente cliente, DtoRichiesta richiesta)
{
this.Add(new OtherNecessaryValidation(dto.OtherProperty));
this.Add(new SpecialAnotherOneValidation(dto.AnotherProperty));
}
}
The root is in common, the difference is what classes (rules) i inject to the list.
Do you think something should be changed?
Thanks
Upvotes: 2
Views: 87
Reputation: 488
I don't understand the need for different validation classes
DefaultValidation vs SpecialValidation
Why don't you have a general validation class with a list of lets say IValidables
that is filled according to your needs. So for each different list it's like you have a total different validation class... does it makes sense?
Upvotes: 1