public static void main(String[] args) { Violations violations = new Violations(); Integer age = AgeValidator.parse("0042", "age", violations); URL url = UrlValidator.parse("http://some.website.com", "url", violations); } // Validator defining all the rules for a valid age value public class AgeValidator { // Collection of validation rules for age values private static final Collection<Validator<String>> VALIDATORS = ...; // Pass in the value to validate, the name of the field // defining the value and the container to collect all // violations (could be a Map<String, ValidationException>) // // a return value of null indicates at least one rule violation public static Integer parse(String value, String name, Violations violations) { try { for (Validator<String> validator : VALIDATORS) validator.validate(value); } catch (ValidationException e) { violations.add(name, e); } return violations.existFor(name) ? null : Integer.parseInt(value); } }