Another solution is to make the set method call a protected function to perform whatever logic you need on assignment. This protected method can of course be overriden in subclasses.
Although unrelated to the issue above, it is always preferable to have a constructor that accepts zero arguments as well your current constructor. See the changes I made in that regard.
super.m
classdef super < handle
properties
x = 1; % some property with a default value
end
methods
function obj = super(value)
% allow for zero-argument construction
if nargin > 0
obj.x = value;
end
end
function set.x(obj, value)
% call another function to check the value as desired,
% and possibly even update it using some computation
value = checkX(obj, value);
% set set the property using the validated value
% (only place we do assignment to avoid infinite recursion)
obj.x = value;
end
end
methods (Access = protected)
function value = checkX(obj, value)
% for example, we require that values be scalar positive
validateattributes(value, {'numeric'}, {'scalar','positive'});
end
end
end
sub.m
classdef sub < super
methods
function obj = sub(value)
% set inherited property if requested
if nargin > 0
obj.x = value;
end
end
end
methods (Access = protected)
function value = checkX(obj, value)
% we could call superclass method to combine effect
value = checkX@super(obj, value);
% or override super-class logic (example: maximum value of 10)
value = min(value,10);
end
end
end