I found one solution. If you put the reset code in a static method, you can call it from within the constructor. Not sure if this is the best but it works.
classdef MySuperClass < handle
properties
a0
a
end
methods(Static)
function reset_static(obj)
obj.a = obj.a0;
end
end
methods
function obj = MySuperClass(a0)
obj.a0 = a0;
MySuperClass.reset_static(obj); % call static method
end
function increment(obj, i)
obj.a = obj.a + i;
end
function reset(obj)
MySuperClass.reset_static(obj); % call static method
end
function disp(obj)
disp(obj.a);
end
end
end
classdef MyClass < MySuperClass
properties
b0
b
end
methods(Static)
function reset_static(obj)
obj.b = obj.b0;
end
end
methods
function obj = MyClass(a0, b0)
obj = obj@MySuperClass(a0);
obj.b0 = b0;
MyClass.reset_static(obj); % call static method
end
function increment(obj, i)
increment@MySuperClass(obj, i);
obj.b = obj.b + i;
end
function reset(obj)
reset@MySuperClass(obj);
MyClass.reset_static(obj); % call static method
end
function disp(obj)
disp@MySuperClass(obj)
disp(obj.b);
end
end
end