Parameter Validation Best Practices

后端 未结 5 2650
一生所求
一生所求 2021-02-20 09:05

Imagine you have an application which is some kind of front-end to all your business logic. This front-end has a lot of DLLs upon which it depends, and the methods in t

5条回答
  •  不思量自难忘°
    2021-02-20 09:49

    As an author of a library, you cannot assume that the consumers have done proper validation of inputs, so you as a library author would want to ensure the arguments are valid before going to work with them.

    As a consumer of a library, if you know what inputs are going to cause the library to fail, why would you pass those inputs to that library? Validate against them so that you can perhaps prompt your user for better inputs or otherwise cancel whatever process you are in.

    The fact that you might be the author of both the library and the consumer is not particularly relevant, in my opinion, as this relationship may very well change.

提交回复
热议问题