I have below the interface. I am using Java 7 and Spring 3.0
public interface Maintain{
void save(Request request);
Request getRequest(String id);
void delete(Request request);
void update(Request request);
}
public class MaintainImpl implements Maintain{
public void save(Request request){
//Need to validate the request before saving.
//Need to throw run time exception if validation fails
}
public void getRequest(String id){
//Need to validate the id before getting the results.
//Need to throw run time exception if validation fails
}
//Similarly i need to implement other 2 methods
}
To validate the requests: I am planning to write one Interface and 4 impl classes which will have validation logic.
public interface validate{
boolan validate();
}
public class SaveRequestValidator implements validate{
public boolean validate(){
//validation logic
}
}
public class GetRequestValidator implements validate{
public boolean validate(){
//validation logic
}
}
public class DeleteRequestValidator implements validate{
public boolean validate(){
//validation logic
}
}
public class UpdateRequestValidator implements validate{
public boolean validate(){
//validation logic
}
}
Now can i perform validations by injecting all these four validators into MaintainImpl.java ?
Is it good practice? Is there any better design? OR can i keep all validations in one class and provide static methods?
Thanks!