Class Hierachie, Inheritance and Access class members

조회 수: 3 (최근 30일)
Bolivar
Bolivar 2013년 9월 6일
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