Can I write validation logic in setter methods?

后端 未结 7 1058
自闭症患者
自闭症患者 2020-12-09 17:49

Are setter methods only used to set the value of attributes as it is passed as argument? Can we write some validation logic before assigning the value to the attributes?

相关标签:
7条回答
  • 2020-12-09 18:24

    It is actually encouraged to validate the input (check whether it fits your data abstraction) to your setter method, so yes you can.

    0 讨论(0)
提交回复
热议问题