Method Attributes
Purpose of Method Attributes
Specifying attributes in the class definition enables you to customize the behavior of methods for specific purposes. Control characteristics like access, visibility, and implementation by setting method attributes. Subclasses do not inherit superclass member attributes.
Specifying Method Attributes
Assign method attributes on the same line as the methods keyword:
methods (Attribute1 = value1, Attribute2 = value2,...) ... end
Table of Method Attributes
Attributes enable you to modify the behavior of methods. All methods support the attributes listed in the following table.
Attribute values apply to all methods defined within the methods...end code block that specifies the nondefault values.
Method Attributes
| Attribute | Values | Description |
|---|---|---|
Abstract |
| If
|
|
| Determines what code can call this method:
|
|
| When |
Sealed |
| If true, the method cannot be redefined in a subclass. Attempting to define a method with the same name in a subclass causes an error. |
|
| Specify as Static Methods provides more information. |
| 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. | |
Method Access List
This class declares an access list for the method Access
attribute:
classdef MethodAccess methods (Access = {?ClassA, ?ClassB, ?MethodAccess}) function listMethod(obj) ... end end end
The MethodAccess class specifies the following method
access:
Access to
listMethodfrom an instance ofMethodAccessby methods of the classesClassAandClassB.Access to
listMethodfrom an instance ofMethodAccessby methods of subclasses ofMethodAccess, because of the inclusion ofMethodAccessin the access list.Subclasses of
ClassAandClassBare allowed to define a method namedlistMethod, andMethodAccessis allowed to redefinelistMethod. However, ifMethodAccesswas not in the access list, its subclasses could not redefinelistMethod.
See Also
metaclass | matlab.metadata.Method