MATLAB Object-Oriented Programming

(Joyce) #1

Calls to Inferior-Class Methods


When you declare a class as inferior to your class, and both classes define a method with
the same name, MATLAB dispatches to your class method regardless of argument order.


Suppose the TemperatureData class that is described in the previous section defines a
set method. If you attempt to assign an object of the TemperatureData class to the
UserData property of an axes object:


td = TemperatureData(x,y);
set(gca,'UserData',td)


The results is a call to the TemperatureData set method. MATLAB does not call the
built-in set function.


To support the use of a set function with inferior classes, implement a set method in
your class that calls the built-in set function when the first argument is an object of the
inferior class.


function set(varargin)
if isa(varargin{1},'matlab.graphics.axis.Axes')
builtin('set',varargin{:})
else
...
end


See Also


More About



  • “Object Precedence in Method Invocation” on page 9-47


See Also
Free download pdf