Modeling validation rules

From FlexRule Wiki
Jump to: navigation, search

Validation rules would validate the structure of objects to make sure they are in a valid state before processing any requests further. Using validation commands you can build a tree to decoratively model validation logic of a hierarchy.

In a complex system model, for example such as the following model

Contact manager system

As you can see in this model, different types of relation exists.

  • Inheritance
  • Aggregation
  • Composition

Validation logic must cover validating all of these relations, associations and values.


The system must maintain the consistency of the model by applying some business rules. These rules must be validated before different scenarios that system supports.

  1. Contact can not be duplicated in database
  2. Contact.Name, Contact.Email, For Person.Title and Company.BusinessNumber
    1. cannot be null or empty
    2. cannot start or end with space padding (if so, has to be removed)
  3. Contact.Email must match: name@domain.ext
  4. Contact must have at least one Address
  5. Address.Line1+Address.Line2 cannot be duplicated
  6. For Address.Line1:
    1. cannot be null or empty
  7. For Address`s City, Country, Line1, Line2 and State:
    1. cannot start or end with space padding (if so, has to be removed)
  8. Phone.Number (if exists)
    1. cannot be null or empty
    2. cannot start or end with space padding (if so, has to be removed)
  9. Phone.Number+Phone.Type cannot be Duplicated
  10. Phone.Number must match: +DDD (DD)DDDD-DDDD

How to model the validation rule

A validation rule may have couple of logic. For example we can create logic to validate a string is not null or empty. And another one to remove padding of string if there is any.

The validation rule can be modelled in the programming language or a high-level language. If it is defined in a high-level language the advantage is it can be changed later without changing the application. However it may not seem necessary in this applications, but if you think about it, for example, Phone.Number format for some countries may not be supported in the first rule version. Or string length constraint be be changed or added to some values later.

Next sections

In the next couple of articles we will cover different aspect of modelling and executing the validation rules using Validation logic.

  1. Introduction to validation rules
  2. Validating hierarchy (Inheritance relation)
  3. Validating association (Aggregation, Composition)
  4. Validation rule execution and collecting results
  5. Pass extra input values to validation rules
  6. Extending validation conditions and actions
  7. How to apply rules under some conditions
  8. Referencing commonly used logic
  9. Sample for Order processing validation logic