I am in the process of writing some validation code based on these assumptions:
- Validation code must be in an external class
- i.e. no data class contains it's own validation
- The same object can be validated in different ways
- e.g. validate syntax only; validate against DB look-ups; validate against duplicates; etc
- Validation output can be different depending on what needs it
- e.g. output a single error message; output a list of all validation errors; similar but in JSON format and including error codes; etc
What combination of OO design patterns are best to solve this? A factory might be a good way to get a specific validator, but are their better approaches?