We've seen one listener and a couple of callbacks already, but it seems important to come back to this concept again because it is used for so many things in the SDK besides ButtonField
and ListField
.
Generally speaking, the listener pattern is used to allow one class to tell another class when something happens to it. In the cases that we've seen so far the FieldChangeListener
is used to let another class listen for notifications that a field has changed. There can be many listeners, all listening to the same event, or there can be none at all. Things that use listeners often employ a "fire and forget" approach, meaning that a response is not required from any of the listeners that may be active. The FieldChangeListener
is just one of the many listeners out there.
A callback is very similar to a listener, but the distinction is one of semantics. A callback is usually used when an object needs two-way communication with just one single object. The ListField
and TreeField...