Subclassing abstract property with defined class, e.g myprop@char, throws an error
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Suppose I have a superclass that I want to use to create an interface:
classdef foo
properties(Abstract)
String@char
end
end
the property is set to char (I could also add vector, i.e. String@char vector , with same consequences).
Now, the concrete class that sets a default to that property is:
classdef subfoo < foo
properties
String = 'something';
end
end
However, in the command line:
>> subfoo
Error using subfoo
The property 'String' restriction defined in class 'subfoo' must match the property definition
in base class 'foo'.
I am forced to declare the property as String@char even in subfoo .
What's the rationale behind this?
PS. I am using an undocumented feature in OO of properties declaration, more details on http://undocumentedmatlab.com/blog/setting-class-property-types.
0 Commenti
Risposte (1)
Igor Varfolomeev
il 29 Mar 2016
By the way, it's still the same in R2016a - even after this syntax feature was officially introduced.
Probably, they treat it like other qualifiers, like "Constant". From some points of view, it sounds reasonable, that you cannot define property as Constant, and then re-define it as non-Constant in an inherited class.
This limitation, most probably, is a result of the same built-in "do not re-define qualifiers" principle. And, personally, I find it much more inconvenient....
0 Commenti
Vedere anche
Categorie
Scopri di più su Subclass Definition in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!