问题
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.
来源:https://stackoverflow.com/questions/41695952/object-with-auto-execute-procedures