Invoke methods and access properties of a subclass by a super class
Show older comments
Hi,
what is the safest way to do that in Matlab, if this is possible?!
I have an abstract relationship between 'smaller' objects and and object, which is composed out of those smaller objects. When I think about it, it must be a 'has-a' relationship. The 'bigger' object has many of the 'smaller' objects. All smaller objects, which the bigger object contains, contribute to build the bigger objects. There is a specific/certain/known number of smaller objects, which build up the bigger object literally.
I have started calculating with nested functions and I have developed (nearly almost) everything that is needed for the smaller objects, but nothing yet for the big object, which has/contains all the smaller objects.
I guess I should define a 'parent class', a 'super class' or a 'base classe' (all mean the same, right?!) for the bigger object and a 'sub class', a 'derived class' or a 'child class' (all mean the same, right?!) for the smaller objects?
I still haven't implemented any stuff for the bigger object yet, which has many smaller objects (inside of it) and I'm not sure how to start this task in a correct manner... Should I use a handle class for this type of inheritence? What do I urgently need to keep in mind, when confronted with such a situation? I've been reading through the matlab help pages and I think I've lost myself in reading?! ...
My 'thinking problem' at the moment is to grasp the idea, that a sub class inherits all methods from the a super class. Well, I haven't defined anything for the super class yet?! There is none for the sub class to inherit from the super class, because the super class just looks like this:
classdef MySuperClass
properties
%well ... It's just that this 'big object' has many of the other objects...
end
methods
%when I know how to think about this correctly, I would like to implement some method(s), which
%takes all the results from EVERY 'smaller object' and adds it up together to get a PROPERTY ...
%Of the super class! There we go! Right now I can think of three to four propertys which I can give
%for this class ...
end
end
My sub class has like 'tons of methods' all performed mainly on just one 'smaller object' at a time. And it has few properties.
What is the best way to communicate between these classes in a way that the super class can access the methods and the properties of the sub class and perform all necessary operations for one element at a time, BUT save the results in one of its properties? Does this sound logical? ...
I would like to implement this with the help of matlab classes and I appreciate your help, your advice and your encourgement!
Accepted Answer
More Answers (0)
Categories
Find more on Construct and Work with Object Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!