Property Validation
The validation model in a property instance is used to restrict the possible values stored in
a
property. The validation mechanism works with two parts
- The validation model.
- The validator.
By separating the validator and the model, it is possible for the application to create multiple
instance of the validator that all use the same validation model to validate values.
Property validation is enforced at the control layer. The view layer also uses validation to
give early
feedback to users about the validity of their changes before they are submitted to the
controller.
The Validation Model
The validation model stores information that will be used to restrict the possible values. It
also contains a link to the validator type that will be used to execute the validation.
The Validator
The validator contains the following information:
- A link to the validation model.
- The value currently being validated.
- A flag indicating if the current value is valid or not.
- An error message indicating what is wrong with the current value. A null error message
indicates that the current value is valid.
To populate the error message, the validator usually contains a deduction rule that uses the
validation model and the current value as inputs and produces an error message if the
validation check failed. The "is valid" flag is normally populated with a
deduction rule that
analyzes if the error message is null or not.