I've got a problem of an inconsistent class state in combination with a PostSet Listener.
classdef myClass < handle
properties (SetObservable,GetAccess = public, SetAccess = public )
propA;
propB;
end
methods
function myClass = myClass()
myClass.propA = zeros(2);
myClass.propB = zeros(2);
addlistener(myClass,{'propA','propB'},'PostSet',@myClass.propChange);
end
end
methods
function setSize(myClass, size)
myClass.propA = zeros(size);
myClass.propB = zeros(size);
end
function propChange(obj,eventData, metaProp)
disp(obj.propA - obj.propB)
end
end
end
The main function is:
m = myClass();
m.setSize([1,2])
The listener functions on propA and propB needs both properties to be the same size. Unfortunately, setSize creates a short moment of inconsistency.
Ways to solve this:
- Is there a way to set propA and propB simultaneously so that the PostSet is executed later?
- I can use a consistency flag as another property. But how to delay the listener execution?
- I can define my own notifications, but everything's working nicely with the predefined function.
Two options can be considered