MATLAB Object-Oriented Programming

(Joyce) #1

  • Trigger events selectively using logical indexing with the values returned by
    event.hasListener. Send event notifications only for array elements that have
    listeners:


ind = event.hasListeners(a,'NameOfEvent');
notify(a(ind),'NameOfEvent',evt)

Listeners in Heterogeneous Arrays


If the input object array is heterogeneous, the class of the array must define the specified
event. You can query the listeners only for events that all objects in the array define.

For example, in the following diagram, the class of a heterogeneous array formed with
objects of classes SpecificA, SpecificB, and SpecificC is RootSuperclass.
Therefore, event.hasListener can find listeners only for the RootEvent event,
because it is the only event common to all array elements.

Create a heterogeneous array with the three most specific classes:

11 Events — Sending and Responding to Messages

Free download pdf