matlab.metadata.Method - Describe MATLAB class method - MATLAB (original) (raw)

Namespace: matlab.metadata
Superclasses: matlab.metadata.MetaData

Describe MATLAB class method

Renamed from meta.method in R2024a

Description

The matlab.metadata.Method class provides information about the methods of MATLAB® classes. Properties of the matlab.metadata.Method class correspond to method attributes and other information that is specified syntactically in the class definition. All properties are read-only.

The matlab.metadata.Method class is a handle class.

Class Attributes

Abstract true
ConstructOnLoad true

For information on class attributes, see Class Attributes.

Creation

You cannot instantiate a matlab.metadata.Method object directly. Obtain amatlab.metadata.Method object from the MethodList property of a matlab.metadata.Class object. MethodList contains an array of matlab.metadata.Method objects, one for each class method.

For example, in this code, replace ClassName with the name of the class whose methods you want to query:

mco = ?ClassName; mlist = mco.MethodList; mlist(1).Name; % name of first method in the list

To obtain a matlab.metadata.Class object from a class instance, use themetaclass function:

Properties

expand all

Name — Method name

character vector

Method name, returned as a character vector.

Description — Short description of method

character vector

Short description of the method, returned as a character vector. For user-defined classes, the text for this property comes from code comments in the method definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your class methods, see Custom Help Text.

DetailedDescription — Detailed description of method

character vector

Detailed description of the method, returned as a character vector. For user-defined classes, the text for this property comes from code comments in the method definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your class methods, see Custom Help Text.

Access — Access level of method

public (default) | protected | private | one or more matlab.metadata.Class objects

The access level of the method, specified as:

Static — Value of method attribute Static

false (default) | true

Value of method attribute Static, returned as logicaltrue or false. If true, the method does not depend on an object of the class and does not require an object as input.

For more information, see Static Methods.

Abstract — Value of method attribute Abstract

false (default) | true

Value of method attribute Abstract, returned as logicaltrue or false. If true, the method has no implementation, but the method has a syntax line that can include arguments. For more information, see Abstract Classes and Class Members.

Sealed — Value of method attribute Sealed

false (default) | true

Value of method attribute Hidden, returned as logicaltrue or false. 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.

Hidden — Value of method attribute Hidden

false (default) | true

Value of method attribute Sealed, returned as logicaltrue or false. When false, the method name appears in the list of methods displayed using themethods or methodsview command. When set totrue, the method name is not included in these listings or when displaying the object in the Command Window.

InputNames — Names of input arguments

character vector | cell array of character vectors

Names of the input arguments used in the function signature, returned as a character vector or cell array of character vectors.

OutputName — Names of output arguments

character vector | cell array of character vectors

Names of the output arguments used in the function signature, returned as a character vector or cell array of character vectors.

DefiningClass — Class that defines method

matlab.metadata.Class object

Class that defines the method, returned as a matlab.metadata.Class object representing the defining class. The defining class is always the most specific class from the perspective of the matlab.metadata.Method object. Therefore, if a subclass overrides an inherited method, then the defining class for the subclass matlab.metadata.Method object is the subclass. Similarly, the defining class for the superclass matlab.metadata.Method object is the superclass.

Examples

collapse all

Use Introspection to Get Information About Methods

Use introspection to get inheritance information about theIntrospectionExample class.

classdef IntrospectionExample % IntrospectionExample Performs basic functions on two numbers % Class methods find the sum and product of its properties. properties % a First property % First of two numeric properties a {mustBeNumeric} = 0

    % b  Second property
    % Second of two numeric properties
    b {mustBeNumeric} = 0
end

methods
    function sum = addNumbers(obj)
        % addNumbers  Sum the properties
        %   Finds the sum of properties a and b.
        sum = obj.a + obj.b;
    end
    function prod = multNumbers(obj)
        % multNumbers  Multiply the properties
        %   Finds the product of properties a and b.
        prod = obj.a*obj.b;
    end
end

end

Create a metaclass instance for IntrospectionExample.

mc = ?IntrospectionExample

mc =

Class with properties:

                Name: 'IntrospectionExample'
         Description: 'Performs basic functions on two numbers'
 DetailedDescription: '  Class methods find the sum and product of its properties.'
              Hidden: 0
              Sealed: 0
            Abstract: 0
         Enumeration: 0
     ConstructOnLoad: 0
    HandleCompatible: 0
     InferiorClasses: [0×1 matlab.metadata.Class]
           Namespace: [0×0 matlab.metadata.Namespace]
             Aliases: [0×1 string]
RestrictsSubclassing: 0
        PropertyList: [2×1 matlab.metadata.Property]
          MethodList: [4×1 matlab.metadata.Method]
           EventList: [0×1 matlab.metadata.Event]

EnumerationMemberList: [0×1 matlab.metadata.EnumerationMember] SuperclassList: [0×1 matlab.metadata.Class]

Access the first method in the MethodList property ofmc to get a matlab.metadata.Method object.

ans = Method with properties:

               Name: 'multNumbers'
        Description: 'Multiply the properties'
DetailedDescription: '    Finds the product of properties a and b.'
             Access: 'public'
             Static: 0
           Abstract: 0
             Sealed: 0
             Hidden: 0
         InputNames: {'obj'}
        OutputNames: {'prod'}
      DefiningClass: [1x1 matlab.metadata.Class]

Version History

Introduced in R2008a

expand all

R2024a: Renamed from meta.method

The namespace and class name of meta.method have been changed tomatlab.metadata.Method. The behavior remains the same.

MATLAB will continue to recognize the old metaclass names in most contexts. However, code that relies on string comparisons to identify metaclasses might need to be updated to continue to work as expected. For example, if mObj in the example below is a matlab.metadata.Method instance, the code under the case statement for 'meta.method' does not execute becauseclass(mObj) returns 'matlab.metadata.Method'.

switch class(mObj) case 'meta.method' % code to execute if mObj is a meta.method instance ... end

To ensure this code continues to work as intended, use an if statement with isa. The isa command recognizes both the old and new names of the class.

if isa(mObj,'meta.method') % code to execute if mObj is a matlab.metadata.Method instance else ... end

If compatibility with older releases of MATLAB is not a concern, you can update 'meta.method' to'matlab.metadata.Method'. However, continue to use the old name if your code needs to run on versions of MATLAB before R2024a.

R2022a: Description and DetailedDescription properties contain text from code comments

For user-defined classes with appropriately placed code comments, theDescription and DetailedDescription properties are populated with text pulled from those comments. For more information on how to use code comments to store custom help text for user-defined classes, see Custom Help Text.