MATLAB OOP - redefine static method

Hi folks,
Following is an OOP question from a guy who knows nothing about OOP, so excuse me in advance :)
There is a built-in MATLAB class, located in matlabroot/toolbox/coder/connectivity/+coder/+rtiostreamtest/Parameters.m (if your version of MATLAB is earlier than R2012b, you might not find it). This class defines a method called getParameterInstance as Static. I just need to add another case to switch statement in this method. I don't want to modify the shipping MATLAB file, and i heard you can "subclass" those shipping classes.
Following documentation, i created a subclass like this:
classdef Parameters < coder.rtiostreamtest.Parameters
methods (Static)
function instance = getParameterInstance(tag, input)
..my very own version of switch-case..
end
end
end
This subclass is located in +myclass/Parameters.m file in MATLAB path. I then issued "rehash toolbox", just in case.
However, i don't see any effect. I'm not overriding the static method of coder.rtiostreamtest.Parameters class.
What am i doing wrong?
Many thanks!

3 Commenti

However, i don't see any effect... What am i doing wrong?
Maybe nothing. What effect did you try to produce and how?
I'm trying to extend existing rtiostreamtest implementation by adding my own connection type. I can do this easily by just adding another case to the switch statement in the getParameterInstance method.
However, i don't want to modify the built-in MATLAB files, hence the question.
After adding another switch case, i'll be calling the rtiostreamtest with my new connection type: rtiostreamtest('shmem','arg1','arg2')
Matt J
Matt J il 8 Lug 2013
Modificato: Matt J il 8 Lug 2013
We need to see the code you executed, a description of what result you got, and a description of what you expected to get.

Accedi per commentare.

 Risposta accettata

per isakson
per isakson il 8 Lug 2013
Modificato: per isakson il 8 Lug 2013
Do you use a call like this?
myclass.Parameters.getParameterInstance( 'two', 'args' )

4 Commenti

Mikhail
Mikhail il 8 Lug 2013
Modificato: Mikhail il 8 Lug 2013
No, the getParameterInstance can't be called directly like that. It is called from rtiostreamtest script (toolbox/coder/connectivity/rtiostreamtest.m).
Your comment though made me think about how MATLAB would know about my class anyway. Probably i would have to modify rtiostreamtest to call to my class instead of the built-in.
Therefore, it would still require to change MATLAB files. I thought it should be somehow possible to use subclassing to override built-in classes transparently, but i was wrong.
Ok, i just created a hierarchy +coder/+rtiostreamtest/Parameters.m in a path higher than built-in. So when rtiotreamtest calls to getParameterInstance, it calls to my class instead of built-in.
Still, this has nothing to do with subclassing. Just an override based on how MATLAB resolves commands.
But it's good enough for me. I achieved what i wanted without changing MATLAB files.
Thanks per isakson, nice hint!
per isakson
per isakson il 8 Lug 2013
Modificato: per isakson il 8 Lug 2013
I don't have access to the Embedded Coder toolbox.
Had the call in the "rtiostreamtest script" been
Parameters.getParameterInstance( 'two', 'args' )
it would have been possible to put a class named Parameters in the top of the Matlab search path. (Not in a package.)
Yes, you will probably need to modify the Matlab script, which should be avoided:-(.
AFAIK: the term built-in class does not include m-files, i.e. not code written in the Matlab language. However, I cannot find a proper definition in the documentation.
Well, the "rtiostreamtest script" has
paramsClass = 'coder.rtiostreamtest.Parameters';
in it, so the path is fully qualified (if that's how it's called).
But as i said earlier, creating the +coder/+rtiostreamtest directory hierarchy higher in MATLAB path with my modified version of Parameters.m did the job.
Oh, sorry if i used built-in term incorrectly. I probably meant shipping.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Construct and Work with Object Arrays in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by