Subclassing abstract property with defined class, e.g myprop@char, throws an error
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Igor Varfolomeev
2016-3-29
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subclass Definition 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!