OO design patterns to use for validation

前端 未结 4 1699
感情败类
感情败类 2021-01-31 21:38

I am in the process of writing some validation code based on these assumptions:

  • Validation code must be in an external class
    • i.e. no data class contains
4条回答
  •  执念已碎
    2021-01-31 22:00

    One size does not fit all! Make it simple!

    Provide validators with common methods/interface to output data, categorize warnings, filter/process warnings raised more than once. Do not create any sophisticated way of validation itself, at least not before writing a few real life validators.

    Move out of the way and let the validators do what they are supposed to do:

    for validator in all_validators:
        validator.validate(model)

提交回复
热议问题