unexpected behavior with matlab.mixin.Heterogeneous
Mostrar comentarios más antiguos
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
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Construct and Work with Object Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!