Ask an expert. Trust the answer.

Your academic and career questions answered by verified experts

Why classes need 'InferiorClasses' to determine which method

Date: 2023-07-31 14:57:53

Why classes need 'InferiorClasses' to determine which method to call when multiple classes have the same method

Document from here .I know how to use InferiorClasses.But I don't know why I need to use InferiorClasses?
 
For example,there is two classes,I don't use InferiorClasses! When I use classA's methods,just use "
 
obj_classA.MyMethod". When I use classB's methods,just use " obj_classB.MyMethod".
 
it's very flexible?So Why classes need 'InferiorClasses' to determine which method to call when multiple classes have the same method?
classdef  classA
       properties
           a;
       end
       methods
         function obj=classA(value)
             obj.a=value;
         end
         function MyMethod (obj,obj_classB)
             disp('The MyMethod of classA Called!');
         end
       end
end
 classdef %(InferiorClasses = {?classA}) classB 
        properties
           b;
        end
         methods
         function obj=classB(value)
             obj.b=value;
         end
         function MyMethod (obj,obj_classB)
             disp('The MyMethod of classB is Called!'); 
         end
         end
  end
  obj_classA = classA(3);
  obj_classB = classB(4);

Expert Answer:

There are several different reasons. The first is that not all of our users are familiar with or comfortable using the object.method syntax. A large subset of our user base prefers function(inputs) syntax, and in that syntax there are situations where you don't want the left-most object to control which class's overload of a method to be called.
 
 
One concrete example is this: plot(ax, obj) where ax is an axes object and obj is an object whose class has a plot method. Which plot method should this call? The axes object is the left-most object, but we don't want it to have to know about every object that could be plotted in it. So many graphics classes will define axes as an InferiorClass, to ensure that plot call would call their plot method rather than the plot method of axes.
 
 
Another is that sometimes the order of the input arguments matters. If A and B are two classes that each overload the minus method, how can we use B's minus to compute A-B? B.minus(A) computes B-A which is not what I want.
 
But if A and B have the same priority, both A.minus(B) and A-B would call A's minus. In this case B would declare A as an InferiorClass to force A-B to call B's minus.

Why Matlabhelpers ?

Looking for reliable MATLAB assignment help? Our expert MATLAB tutors deliver high-quality, easy-to-understand solutions tailored to your academic needs. Whether you're studying at Monash University, the University of Sydney, UNSW, or the University of Melbourne, we provide trusted MATLAB assistance to help you excel. Contact us today for the best MATLAB solutions online and achieve academic success!

MATLAB Assignment Help Services

Personalized Tutoring: Get one-on-one guidance from our MATLAB experts. Whether you're tackling basic concepts or advanced algorithms, we provide clear, step-by-step explanations to help you master MATLAB with confidence.

Assignment Assistance: Struggling with tight deadlines or complex assignments? Our team offers end-to-end support, from problem analysis to code development and debugging, ensuring your assignments meet the highest academic standards.

Project Development: Need expert help with your MATLAB research project? We assist in designing and implementing robust solutions, covering project planning, data collection, coding, simulation, and result analysis.

Coursework Support: Enhance your understanding of MATLAB with our comprehensive coursework assistance. We help you grasp lecture concepts, complete lab exercises, and prepare effectively for exams.

Thesis and Dissertation Guidance: Incorporate MATLAB seamlessly into your thesis or dissertation. Our experts provide support for data analysis, modeling, and simulation, ensuring your research is methodologically sound and impactful.

Contact us on WhatsApp for MATLAB help

Contact us on Telegram for MATLAB solutions