MATLABハンドルクラスのプロパティpostSetは非常に便利ですが、ネストされたクラスを別々にトリガーすることができれば幸いです。スクリプト例でネストされたMatlabプロパティリスナー
classdef parentClass < handle
properties (SetObservable = true)
childClass
end
methods
function this = parentClass()
this.childClass = childClass();
end
end
end
と
classdef childClass < handle
properties (SetObservable = true)
value
end
methods
function this = childClass()
this.value = 0;
end
end
end
"runTestの"
p = parentClass();
addlistener(p.childClass,'value','PostSet',@(o,e)disp('child value set'));
addlistener(p,'childClass','PostSet',@(o,e)disp('parent value set'));
p.childClass.value = 1;
結果が(予想通り)
>> runTest
child value set
:例示のための2つのネストされたクラスで最小の例
ハウ版、私は結果は次のようになり、このようなことの両方のレベルでのプロパティの変更を検出するためのエレガントな方法を探しています:これを行うには
>> runTest
child value set
parent value set
提案をいただきありがとうございます。私は、あなたの "実践的な"提案が行く方法だと信じています。 –