The property 'someprop' restriction defined in class 'myobj2_class' must match the property definition in base class 'myobj1_class'.
1 次查看(过去 30 天)
显示 更早的评论
Does anyone think that it would be nice to modify the behavior of the "Restrict Property Values to Specific Classes" feature, to allow the following use case:
"myprop1_class.m":
classdef myprop1_class
end
"myprop2_class.m":
classdef myprop2_class < myprop1_class
end
"myobj1_class.m":
classdef myobj1_class
properties (Abstract)
someprop@myprop1_class
end
end
"myobj2_class.m":
classdef myobj2_class < myobj1_class
properties
someprop@myprop2_class
end
end
"test_inheritance.m":
myobj = myobj2_class();
% R2016a says:
%
% Error using myobj2_class The property 'someprop' restriction defined in
% class 'myobj2_class' must match the property definition in base class
% 'myobj1_class'.
%
% Error in test_inheritance (line 3)
% myobj = myobj2_class();
%
%
% That's a pity.
% I wished such a syntax would be allowed....
For me, such a change looks very nice. It perfectly matches the principle, that an object “myobj2” of a class “MyClass2”, inherited from “MyClass1”, perfectly passes the “isa(myobj2,MyClass1)” check, just like in case of this new “Restrict Property Values to Specific Classes” syntax.
Moreover, note, that this check could not be implemented with a custom set(..) method for myobj1_class, cause Matlab does not allow to implement set methods for Abstract properties.
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Class File Organization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!