Note: I would recommeng giving a name other than set to your property. That name is already overloaded enough by matlab.
function set.propertyname(object, valuetoset)
end
with your property name this would be
function set.set(this, value)
if ~strcmp(class(value), somevalidclass)
error('invalid class supplied to set');
end
this.set = value;
end
However, as I said, this property set method must be implemented in the class that defines the property, that is your base class, not the derived class. The workaround is from the set method to call another method that does the validation and is overridden by the derived class:
classdef SimpleList < handle
properties
set;
end
methods
function set.set(this, value)
isok = this.validateset(value);
if ~isok
error('invalid type of variable for set property)
end
this.set = value;
end
end
methods (Access = protected)
function isok = validateset(this, value)
isok = true;
end
end
end
classdef ObjList < SimpleList
methods (Access = protected)
function isok = validateset(this, value)
isok = strcmp(class(value), 'double');
end
end
end
Best Answer