org.srplib.validation.AbstractValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of srp-validation Show documentation
Show all versions of srp-validation Show documentation
Single Responsibility Principle (SRP) libraries collection
package org.srplib.validation;
/**
* Base abstract class for validators implementations.
*
* This base class simplifies validators creation because subclasses are responsible only for checking validity condition
* and providing validation error. This class populates validatable with validation error (if any)
*
* TODO: does this class make sense? Subclasses have no chance to add value validation error.
*
* @author Anton Pechinsky
*/
public abstract class AbstractValidator implements Validator {
@Override
public void validate(Validatable validatable) {
if (!isValid(validatable)) {
validatable.addError(newError());
}
}
/**
* Subclasses should implement this method and check validatable for errors.
*
* @param validatable Validatable an object to validate
* @return true if specified validatable is valid, false
otherwise
*/
protected abstract boolean isValid(Validatable validatable);
/**
* Subclasses should implement this method and
* @return
*/
protected abstract ValidationError newError();
}