# The Rules

Several useful rules are provided in the interest that the application programmer can use them with a minimum of programming. These are classes that implement `ValidationRule` and can be used by application logic:

- ProtectRule will protect one or more properties on an entity.
- RequireRule will require that a property be populated.
- AllowRule allows a value to be populated.
- AllowAndRequireRule both allows and requires that a property be populated.
- DecimalRule provides some common validations against decimal data types.
- CustomRule will create a rule out of a CustomValidation class implementing logic that just cannot be handled by existing rules.
- RestrictRule will restrict a property to a set of values.

Each of the rules above provides standard rules that represent similarly configured rules that are used repeatedly in the system. These standard rules can be created via static factory methods on the rules themselves. Consider the following standard rule:

    			/**
    			 * Protect the dependant property when the primary property is equal to the supplied lookup value.
    			 *
    			 * @param ruleId a unique ruleId
    			 * @param description a description
    			 * @param primaryProperty the property that the condition depends on
    			 * @param dependantProperty the property that is protected when the condition is true
    			 * @param primaryLookupValue a {@link Lookup} value that the primary property must equal for the dependant property
    			 *                            to be protected
    			 * @return a new rule
    			 */
    			public static ProtectRule
    			   dependantPropertyWhenPrimaryMathesLookup
    			        (String ruleId,
    			         String description,
    			         SingleValueProperty primaryProperty,
    			         SingleValueProperty dependantProperty,
    			         Lookup primaryLookupValue)

What this rule does is to prevent one property from being changed (the dependant property) when another property (the primary property) matches a certain value. An example would be "the freeze date/time cannot be changed when the status is 'frozen'". In this case, the dependant property would be freeze date/time and the primary property would be the status. The lookup value of frozen would be passed in as the lookup value.

Parent topic: Validation Rules