Is there a way to create an object with auto execute procedures? For example if a variable within this object has changed a private procedure kicks in and starts to do something?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
The language offers no such functionality. You have to implement it yourself.
Typically that's done by hiding the variable as a private
, or better a strict private
, and then ensure that all access to the variable is routed through a property. Then you can take whatever action you need in the property setter method.