Hi,
I'm trying to modify an immutable/protected property of a sub class, using a superclass method or an external utility function (I'm trying to use this function in the subclass's constructor, of course).
Example (of what I would like to do):
classdef Sup methods function self = setProperties(self, varargin) % This method sets the properties of the class
% the input arguments come in the form 'propname1', val1, 'propname2', val2, ...
... end % setProperties
end % methods
end % classdef Sup
classdef sub < Sup properties (SetAccess = immutable) prop1 prop2 prop3 end % properties
methods function self = sub(varargin) % constructor
self = setProperties(self, varargin) end % sup
end % methods end % classdef sub
>> SomeObj = sub('prop1', 1, 'prop2', 10, 'prop3', 100);
This code doesn't work, I get the error message 'You cannot set the read-only property 'prop1' of sub.'
I'm OK with setting sub's properties to be protected, but I wouldn't want them to be public. I'm also OK with the idea that setProperties would be an external utility function (not defined in the superclass), but then again, I'm not able to use setProperties in the constructor of sub.
Would appreciate your help on that.
Thank you,
Avihay
Best Answer