Class Hierachie, Inheritance and Access class members

2 次查看(过去 30 天)
Hallo,
I've difficuty accessing subclass methods. Any try results in MATLAB error: Method 'AddListener' is not defined for class 'baseStation' or is removed from MATLAB's search path.
my classes design looks like this :
classdef super1 < handle
....
methods
AddListener(obj,objmob);
end
end
classdef super2 < handle
...
methods
AddListener(obj,ojbbts,ojbmob)
end
end
classdef subclass < super1&super2
.................
methods
AddListener(obj,ojbmob,ojbbts);
end
end
subclass actualy call super classes AddListener methods :
AddListener@super1(obj,ojbmob);
AddListener@super2(obj,objmob,objbts);
but also perform other processing befor and after these call. The documentation state to avoid access conflict the following condition among other should hold: The subclass redefines the method to disambiguate the multiple definitions across all superclasses. This means that the superclass methods must not have their Sealed attribute set to true.
All the methods are defined in separated file from that class definition are. What I am doing wrong?
Thanks

回答(1 个)

Titus Edelhofer
Titus Edelhofer 2013-9-6
Hi,
might be some typo? Should (and does) work like you write:
super1.m:
classdef super1 < handle
methods
function AddListener(obj,objmob)
disp('super1.AddListener')
end
end
end
super2.m:
classdef super2 < handle
methods
function AddListener(obj,objbbts, objmob)
disp('super2.AddListener')
end
end
end
subclass.m:
classdef subclass < super1&super2
methods
function AddListener(obj,objmob,objbts)
AddListener@super1(obj,objmob);
AddListener@super2(obj,objmob,objbts);
end
end
end
And now the test:
>> x = subclass
x =
subclass with no properties.
>> x.AddListener(2,3)
super1.AddListener
super2.AddListener
Titus
  3 个评论
Titus Edelhofer
Titus Edelhofer 2013-9-6
Hi Sean,
yes, could me a mix up of the addlistener method of the handle class and the (totally independent) AddListener method of the example ...
Titus
Bolivar
Bolivar 2013-9-6
Hi Titus,
I've checked it over and over wehter there were some tipos mistakes but nothing. As you saind it may lay on confusion between built-in addlistener and my AddListeners' methods. In fact they encapsulate built-in addlistener.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Construct and Work with Object Arrays 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by