Business Validation Logic Code Smell

后端 未结 14 1262
醉酒成梦
醉酒成梦 2021-01-17 17:54

Consider the following code:

partial class OurBusinessObject {
    partial void OnOurPropertyChanged() {
        if(ValidateOurProperty(this.OurProperty) ==          


        
14条回答
  •  灰色年华
    2021-01-17 18:18

    I think your validation logic should raise an exception if asked to use an invalid value. If your consumer wants to use a default value, it should ask for it explicitly, either through a special, documented value or through another method.

    The only kind of exceptions I can think would be forgivable would be, like, normalizing case, like in email fields to detect duplicates.

提交回复
热议问题