Should i validate parameters in constructor?

前端 未结 4 1721
谎友^
谎友^ 2021-02-07 08:09

I am creating a web application following the MVC pattern.

In effective Java the author mentions to validate the parameters in the constructor of the class when creatin

4条回答
  •  遥遥无期
    2021-02-07 08:30

    I would suggest validating the data in your domain and returning a (custom) exception when fields aren't filled in correctly. This way you'll be able to implement a different UI without having to do the entire validating process again, it's best to separate this as much as possible.

提交回复
热议问题