Thursday, January 14, 2010

Thoughts on validation

Would I miss anything if I guess that a validation rule applied to a single entity can be either of the two:
  1. An extention to a standard general-purpose type like int, double, String, etc that constrains the domain of possible values to the actual business domain. When I declare a String property as not null and having at most 16 characters, I actually give a hint to the framework to force the corresponding restriction on assigned values. Alternatively I could probably declare a new type like NonNullString16 and use it instead. Possibly a good example is the price of some asset that should never be less than zero. This requirement can be captured by NonNegativeDecimal type or even more specialized AssetPrice type. However, building a custom type for every particular situation seems rather irrational and hardly doable in most cases dut to a number of technical problems.
  2. A complex check on several properties correlated by some law. Examples:
    for an employee the graduation date cannot precede the date of birth, for a market quote bid price cannot be higher than offer price, the number of idle resources cannot exceed the overall pool size, etc.
There is also sort of mess in SQL where #1 maps to NOT NULL constraint and size restriction on the column data type, and #2 is reflected by a CHECK constraint. Or is it a mess at all?

No comments:

Post a Comment