3.2
Static Notification
The static approach is the most convenient option, but it
is not always possible. Writing a static change notification handler requires
that, for a class whose trait attribute changes you are interested in, you
write a method on that class (or a subclass). Therefore, you must know in
advance what classes and attributes you want notification for, and you must be
the author of those classes. Static notification also entails that every
instance of the class has the same notification handlers.
To indicate that a particular method is a static
notification handler for a particular trait, you have two options:
· Apply the
@on_trait_change decorator to the method.
·
Give the method a special name based on the name of the trait
attribute it “listens” to.
|