开发者

Question about objects

开发者 https://www.devze.com 2023-02-09 11:11 出处:网络
Hey guys, i\'m having some trouble with this: In the object \"consumer\" i need to do a validation for开发者_StackOverflow the property Nit.

Hey guys, i'm having some trouble with this:

In the object "consumer" i need to do a validation for开发者_StackOverflow the property Nit.

But i don't know where to put this validation.

Do i have to put it where i set the value,

In a public function to validate the content before setting the value,

or a method inside the object "validateNit"

I'm still learning and i have that doubt.

Ty so much for your help, and sorry about the crappy English.


if the property is set just once on initialization, then validate it during object initialization, with a method validateNit. if it can be set/modified at any time with, say, a setNit(newNit) method, you can call validateNit() from setNit().

0

精彩评论

暂无评论...
验证码 换一张
取 消