Modifying private properties of one class array which is itself a private property of a bigger independent class

1 view (last 30 days)
Hello dear Matlab community!
I've been using the answers and the knowledge database for many years. This time, however, I cannot find a thread dealing with my issue. For your convenience, I have created a graphical summary of my question in the attached picture.
I have developed two independent classes:
● one for processing the data from a single experiment (let's clal it the 'SmallClass');
● the other one ('BigClass') conglomerates different experiments and stores their data in an array of the previous class.
It is important to stress out that the two classes are INDEPENDENT (they are not superclass and subclass, there is nothing derived or inherited). It was done because of historical reasons and there is no intention to make it differently by now.
In both classes, all properties ar private. Of course, they have their own 'get' and 'set' methods.
Now let's say I have some data in my big class and want to modify the private property of some particular class stored within. The class itself has an appropriate 'set' method, but since it is private in the view of the big class, I am not allowed to change it:
>> BigClass.SmallClass(1)=BigClass.SmallClass(1).set_some_property({args});
You cannot set the read-only property 'SmallClass' of BigClass.
In order to change those propeties, I have created the wrapping functions in the BigClass that simply call the appropriate 'set' methods in the SmallClass using the same syntax, for instance:
>> BigClass=BigClass.set_some_property(which_small_class,{args});
This, on the other hand, is basically copy-pasting the calls from one class into the other. If anything gets changed in SmallClass, I would have to meticulously copy-paste the wrapping function inside the BigClass.
Is there any way for Matlab to automatically recognize which method of the SmallClass is being called from the BigClass and avoid reusing the same code? My colleague mentioned that in C, virtual functions would do the job, but they do not exist in Matlab as far as I know.
Your tips would be greatly appreciated!
  1 Comment
Sudhakar Shinde
Sudhakar Shinde on 27 Oct 2020
Edited: Sudhakar Shinde on 27 Oct 2020
1. May be you have already look on abstract class as you mentioned in above (they are not superclass and subclass, there is nothing derived or inherited).
2. If you are using unittest environment you may be interested in Shared Fixtures

Sign in to comment.

Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!