Find abstract methods and properties
absMembers = meta.abstractDetails(___)
meta.abstractDetails(ClassName) displays a list of abstract methods and properties for the class with name ClassName. Use the fully specified name for classes in packages. MATLAB® displays all public and protected abstract methods and properties, including those declared Hidden.
absMembers = meta.abstractDetails(___) returns an array of the metaclass objects corresponding to the abstract members of the class, and can include any of the input arguments in previous syntaxes. If the class has both abstract methods and abstract properties, absMembers is a heterogeneous array of class meta.MetaData containing meta.method and meta.property objects.
A class can be abstract without defining any abstract methods or properties if it declares the Abstract class attribute. In this case, meta.abstractDetails returns no abstract members for that class, but the class is abstract. See Determine If a Class Is Abstract for more information.
Name of the class specified as a character string (for example, 'MyClass')
meta.class object representing the class (for example, ?MyClass)
Define the class, AbsBase, with an abstract property:
classdef AbsBase properties (Abstract) Prop1 end methods(Abstract) result = methodOne(obj) output = methodTwo(obj) end end
Pass the class name (AbsBase) as a string:
meta.abstractDetails displays the names of the abstract properties and methods defined in the class AbsBase.
Abstract methods for class AbsBase: methodTwo % defined in AbsBase methodOne % defined in AbsBase Abstract properties for class AbsBase: Prop1 % defined in AbsBase
Pass a meta.class object representing the AbsBase class and return the metaclass objects for the abstract members. Use the definition of the AbsBase class from the previous example.
mc = ?AbsBase; absMembers = meta.abstractDetails(mc);
absMembers is a heterogeneous array containing a meta.property object for the Prop1 abstract property and meta.method objects for the methodOne and methodTwo abstract methods.
List the names of the metaclass objects.
for k=1:length(absMembers) disp(absMembers(k).Name) end
methodTwo methodOne Prop1
Derive the SubAbsBase class from AbsBase, which is defined in a previous example.
classdef SubAbsBase < AbsBase properties SubProp = 1; end methods function result = methodOne(obj) result = obj.SubProp + 1; end end end
Display the names of the abstract members inherited by SubAbsBase.
meta.abstractDetails('SubAbsBase') Abstract methods for class SubAbsBase: methodTwo % defined in AbsBase Abstract properties for class SubAbsBase: Prop1 % defined in AbsBase
To make SubAbsBase a concrete class, you need to implement concrete versions of methodTwo and Prop1 in the subclass.