alt sınıf üst sınıfı yöntemlerinden herhangi reimplement etmezse (veya reimplemented yöntemleri göz ardı ince iseniz), değil alt sınıf yöntemlerinin bir listesini bulmak için fonksiyonları METHODS ve SUPERCLASSES kullanabilirsiniz ayrıca süper-sınıfların herhangi birinin yöntemleri. Örneğin: nasıl sonuç
subMethods =
'set' 'get' 'setdisp' 'getdisp' 'empty'
Not:
%# 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}
Bu örnek için sonuç: Bu soru çözüldü rağmen
>> 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'
Yeni stil MCOS sınıfları (classdef dosyalarıyla birlikte) veya eski stil sınıfları kullanıyor musunuz? –
classdef dosyaları. –