Contenuto principale

Event Attributes

Specify Event Attributes

The following table lists the attributes you can set for events. To specify a value for an attribute, assign the attribute value on the same line as the event keyword. For example, all the events defined in the following events block have protected ListenAccess and private NotifyAccess.

events (ListenAccess = protected, NotifyAccess = private)
   EventName1
   EventName2
end

To define other events in the same class definition that have different attribute settings, create another events block.

Event Attributes

Attribute Name

Class

Description

Hidden

logical Default = false

If true, event does not appear in list of events returned by events function (or other event listing functions or viewers).

ListenAccess

  • enumeration, default = public

  • matlab.metadata.Class object

  • cell array of matlab.metadata.Class objects

Determines where you can create listeners for the event.

  • public — Unrestricted access

  • protected — Access from methods in class or subclasses

  • private — Access by class methods only (not from subclasses)

  • List classes that have listen access to this event. Specify classes as matlab.metadata.Class objects in the form:

    • A single matlab.metadata.Class object

    • A cell array of matlab.metadata.Class objects. An empty cell array, {}, is the same as private access.

    See Class Members Access

NotifyAccess
  • enumeration, default = public

  • matlab.metadata.Class object

  • cell array of matlab.metadata.Class objects

Determines where code can trigger the event

  • public — Any code can trigger event

  • protected — Can trigger event from methods in class or derived classes

  • private — Can trigger event by class methods only (not from derived classes)

  • List classes that have notify access to this event. Specify classes as matlab.metadata.Class objects in the form:

    • A single matlab.metadata.Class object

    • A cell array of matlab.metadata.Class objects. An empty cell array, {}, is the same as private access.

    See Class Members Access

Framework attributes

Classes that use certain framework base classes have framework-specific attributes. See the documentation for the specific base class you are using for information on these attributes.

Event Access List

This class declares an access list for the event ListenAccess attribute:

classdef EventAccess
   events (NotifyAccess = private, ListenAccess = {?ClassA, ?ClassB})
      Event1
      Event2
   end
end

The class EventAccess specifies the following event access:

  • Limits notify access for Event1 and Event2 to EventAccess; only methods of the EventAccess can trigger these events.

  • Gives listen access for Event1 and Event2 to methods of ClassA and ClassB. Methods of EventAccess, ClassA, and ClassB can define listeners for these events. Subclasses of EventAccess cannot define listeners for these events.

See Also

Topics