org.srplib.validation.Validatable 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;
import java.util.List;
/**
* Encapsulates an object which can be validated.
*
* Validatable is unaware of UI framework and contains only validation specific logic.
*
* Usage patterns:
*
* - Extract value from to be-validated-component and wap it with Validatable implementation (e.g. DefaultValidatable).
* - Pass resulting validatable to all associated validators
* - Query validatable.hasErrors() method
*
*
*
*
* @author Anton Pechinsky
*/
public interface Validatable {
/**
* Returns value to be validated.
*
* @return an object representing value.
*/
T getValue();
/**
* Tests if this object has errors or not.
*
* @return true if object has errors, false
otherwise
*/
boolean hasErrors();
/**
* Adds error to this object.
*
* @param error ValidationError an error.
*/
void addError(ValidationError error);
/**
* Returns validation error associated with this object.
*
* @return a List of validation errors. If there are errors then empty list is returned.
*/
List getErrors();
/**
* Returns a reference to component which is being validated.
*
* @return Object validation context
*/
Object getContext();
}