unexpected behavior with matlab.mixin.Heterogeneous
이전 댓글 표시
There seems to be an issue with inheritance when using
"matlab.mixin.Heterogeneous."
To illustrate consider two objects (code at bottom): Child, which inherits from Parent. The superclass method "changeParentVariable" is useless only when everything inherits from matlab.mixin.Heterogeneous. One would hope that root of inheritance (handle or matlab.mixin.Heterogeneous) would be immaterial. How can I make correct the behavior of matlab.mixin.Heterogeneous?
Behavior when everything inherits from "handle:"
>> test = Child(1,2)
test =
Child with properties:
childVariable: 2
parentVariable: 1
>> changeParentVariable(test,3)
>> test
test =
Child with properties:
childVariable: 2
parentVariable: 3
Behavior when everything inherits from "matlab.mixin.Heterogeneous:"
test = Child(1,2)
test =
Child with properties:
childVariable: 2
parentVariable: 1
>> changeParentVariable(test,3)
>> test
test =
Child with properties:
childVariable: 2
parentVariable: 1
...the superclass method was unable to modify the object when everything inherits from "matlab.mixin.Heterogeneous."
THE CODE
classdef Parent < handle % or matlab.mixin.Heterogeneous
properties
parentVariable = [];
end
methods
function obj = Parent()
obj.parentVariable = 0;
end
function changeParentVariable(obj,a)
obj.parentVariable = a;
end
end
end
classdef Child < Parent
properties
childVariable = [];
end
methods(Sealed)
function obj = Child(a,b)
obj = obj@Parent();
obj.parentVariable = a;
obj.childVariable = b;
end
end
end
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Construct and Work with Object Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!