Validating domain objects
Further, using this technique, we have implemented a set of validators such that validation against the property will only take place if a second property meets a given dependency constraint.
Also, we have implement optional validation ina similar manner such that, of the specified attributes, only those flagged as Optional will be executed if a second property meets a given dependency constraint.
We have defined these as constrained validators and they are simple to implement.
When the reflection engine has access to the desired property value, you then reflect once more over the object to find the constraining property value and validate as required...simples!
Validate all input your application has, but be more confident with the internals. Let me ask you more clarification questions: Our goal is make sure any object exists only in valid states:
With said above, we can build object with invalid email - is it valid or invalid state?
For example, an order item object always has to have a quantity that must be must be a positive integer, plus an article name and price.