The property 'someprop' restriction defined in class 'myobj2_class' must match the property definition in base class 'myobj1_class'.
조회 수: 2 (최근 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에서 Sample Class Implementations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!