Class Hierachie, Inheritance and Access class members

2 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Titus Edelhofer
Titus Edelhofer il 6 Set 2013
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 Commenti
Titus Edelhofer
Titus Edelhofer il 6 Set 2013
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 il 6 Set 2013
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.

Accedi per commentare.

Categorie

Scopri di più su Construct and Work with Object Arrays in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by