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 ?

Our Matlab assignment helpers for online MATLAB assignment help service take utmost care of your assignments by keeping the codes simple yet of high-quality. We offer the most reliable MATLAB solutions to students pursuing their Computer Science course from the Monash University, the University of Sydney, the University of New South Wales, the University of Melbourne; to name a few. Approach us today for best Matlab solutions online!

Our Comprehensive Matlab Assignment Help Services

Personalized Tutoring:Our team of MATLAB experts offers one-on-one tutoring sessions tailored to your specific needs. Whether you’re struggling with basic concepts or advanced algorithms, we provide clear, step-by-step guidance to help you understand and master MATLAB.

Assignment Assistance:Facing tight deadlines or complex assignments? We’re here to help! From initial problem analysis to code development and debugging, we offer full-spectrum support to ensure your assignments meet the highest standards.

Project Development: Need help with a research project? Our specialists can assist you in designing and implementing robust MATLAB solutions. We cover everything from project planning and data collection to coding, simulation, and result analysis.

Coursework Support: We provide comprehensive support for your coursework, helping you understand lectures, complete lab exercises, and prepare for exams. Our goal is to ensure you grasp the core principles and practical applications of MATLAB.

Thesis and Dissertation Guidance:Writing a thesis or dissertation? Our experts can assist you in incorporating MATLAB for data analysis, modeling, and simulation. We help you develop a strong methodological framework and ensure your research stands out.

whatsApp order on matlabhelpers.com

telegram order on matlabsolutions.com