Subclassing abstract property with defined class, e.g myprop@char, throws an error

2 views (last 30 days)
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.

Answers (1)

Igor Varfolomeev
Igor Varfolomeev on 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....

Community Treasure Hunt

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

Start Hunting!