MATLAB Object-Oriented Programming

(Joyce) #1

classdef (InferiorClasses = {?classA}) classB
...
end


The methodA method is defined with two input arguments, one of which is an object of
classB:


classdef classA
methods
function methodA(obj,obj_classB)
...
end
end


classB does not define a method with the same name as methodA. Therefore, the
following syntax causes MATLAB to search the path for a function with the same name as
methodA because the second argument is an object of a dominant class. If a function with
that name exists on the path, then MATLAB attempts to call this function instead of the
method of classA and most likely returns a syntax error.


obj = classA(...);
methodA(obj,obj_classB)


Dot notation is stricter in its behavior. For example, this call to methodA:


obj = classA(...);
obj.methodA(obj_classB)


can call only methodA of the class of obj.


Referencing Names with Expressions—Dynamic Reference


You can reference an object's properties or methods using an expression in dot-
parentheses syntax:


obj.(expression)


The expression must evaluate to a char vector that is the name of a property or a
method. For example, the following statements are equivalent:


obj.Property1
obj.('Property1')


Method Invocation
Free download pdf