Data Validation Design Patterns

前端 未结 5 1526
灰色年华
灰色年华 2020-12-13 16:14

If I have a collection of database tables (in an Access file, for example) and need to validate each table in this collection against a rule set that has both common rules a

5条回答
  •  轮回少年
    2020-12-13 16:25

    Just an update on this: I decided to go with the Decorator pattern. That is, I have one 'generic' table class that implements an IValidateableTable interface (which contains validate() method). Then, I created several validation decorators (that also implement IValidateableTable) which I can wrap around each table that I'm trying to validate.

    So, the code ends up looking like this:

    IValidateableTable table1 = new GenericTable(myDataSet);
    table1 = new NonNullNonEmptyColumnValidator(table1, "ColumnA");
    table1 = new ColumnValueValidator(table1, "ColumnB", "ExpectedValue");
    

    Then, all I need to do is call table1.Validate() which unwinds through the decorators calling all of the needed validations. So far, it seems to work really well, though I am still open to suggestions.

提交回复
热议问题