Class Hierachie, Inheritance and Access class members
    4 views (last 30 days)
  
       Show older comments
    
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
0 Comments
Answers (1)
  Titus Edelhofer
    
 on 6 Sep 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 Comments
  Titus Edelhofer
    
 on 6 Sep 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
See Also
Categories
				Find more on Handle Classes in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

