The property 'someprop' restriction defined in class 'myobj2_class' must match the property definition in base class 'myobj1_class'.
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Class File Organization finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!