यदि आपका सबक्लास सुपरक्लास के किसी भी तरीके को पुन: कार्यान्वित नहीं करता है (या यदि आप अनुपूरक तरीकों को अनदेखा करने के साथ ठीक हैं), तो आप उप-वर्ग विधियों की सूची खोजने के लिए METHODS और SUPERCLASSES फ़ंक्शंस का उपयोग कर सकते हैं किसी भी सुपरक्लास के तरीके भी। उदाहरण के लिए:
%# some class name
clname = 'hgsetget';
%# obtain class meta-info
mt = meta.class.fromName(clname);
%# get name of class defining each method
cdef = arrayfun(@(c)c.Name, [mt.MethodList.DefiningClass], 'Uniform',false);
%# keep only methods that are defined in the subclass
subMethods = {mt.MethodList(ismember(cdef,clname)).Name}
इस उदाहरण के लिए परिणाम:
>> obj = 'hgsetget'; %# A sample class name
>> supClasses = superclasses(obj)
supClasses =
'handle' %# Just one superclass, but what follows should handle more
>> supMethods = cellfun(@methods,supClasses,... %# Find methods of superclasses
'UniformOutput',false);
>> supMethods = unique(vertcat(supMethods{:})); %# Get a unique list of
%# superclass methods
>> subMethods = setdiff(methods(obj),supMethods) %# Find methods unique to the
%# subclass
subMethods =
'get'
'getdisp'
'set'
'setdisp'
क्या आप नई शैली एमसीओएस कक्षाओं (क्लासडेफ फाइलों के साथ), या पुरानी शैली कक्षाओं का उपयोग कर रहे हैं? –
classdef फाइलें। –