I have a MATLAB class called super:
classdef super < handle
properties
aString = '';
end
methods
function obj = super(obj, value)
obj.aString = value;
end
function set.aString(obj, value)
obj.aString = value;
end
end
end
I want to override the set function in a subclass derived from 'super':
classdef sub < super
%// Property 'aString' is inherited from super
methods
function obj = sub(obj, value)
%// Must include call to super constructor otherwise MATLAB will by
%// default call constructor with no arguments but my super class
%// requires one argument in constructor. This call should probably
%// super set method. But I don't care.
obj = obj@super('');
%// Now that super constructor has returned, call sub overriding
%// set method
obj.aString = value;
end
function set.aString(obj, value)
obj.aString = value;
end
end
end
The code above gives me the following error:
> Cannot define property 'aString' in class 'sub' because the property
> has already been defined in the superclass 'super'
Adding the property definition to 'sub' results in the same error.
I have also unsuccessfully tried using "Abstract" as a workaround, where I define an Abstract class:
classdef (Abstract) bloat < handle
properties (Abstract)
aString
end
end
and then try implementing 'super' as a child of 'bloat':
classdef super < bloat
%// Remainder of super code remains the same
Which did not work as I guess by the time 'sub' inherites, 'aString' is "concrete". I then, in addition to the above modification, tried modifying 'sub' to include 'boat' in its class definition:
classdef sub < super & bloat
%// Remainder of super code remains the same
This also did not work.
I have been unable to find any MATLAB documentation that specifically says: "You cannot modify set and get methods".
I'm hoping that my syntax is simply incorrect, but from searching I now fear that MATLAB does not allow this (either as a bug or by design).
EDIT: I am using MATLAB 2013a
Thank you