I went back to the author and brought up these techniques. He agrees that the level of hackery is unforuntate, but this is what we agreed to:
- An analyze_protected_static method was added to let us access any superclass analyze method.
- The constructor of Interpolator calls that static method of the superclass to get the instance data.
classdef DataAnalyzer < HandleCompatibleSuperClass
methods
function obj = DataAnalyzer(dat,varargin)
obj = obj@HandleCompatibleSuperClass(varargin{:})
% ... lengthy constructor using dat to set immutable properties.
end
% This method is just a wrapper for the protected, static method.
y_results = analyze(obj,x_queries)
% ... lots of other user methods to analyze data
end
methods(Static,Access=protected)
% The true, slow analysis method.
y_results = analyze_protected_static(obj,x_queries)
end
end
Then the Interpolator subclass just constructs the domain data from the static method.
classdef DataInterpolator < DataAnalyzer
properties(SetAccess=immutable,GetAccess=private)
DomainX (:,1)
RangeY (:,:)
end
methods
function obj = DataInterpolator(x_domain,dat,varargin)
% Construct object
obj = obj@DataAnalyzer(dat,varargin{:});
obj.DomainX = x_domain;
obj.RangeY = DataAnalyzer.analyze_protected_static(obj,obj.DomainX);
end
function y_results = analyze(obj,x_queries)
% No if cases; YAY!
y_results = interp1(obj.DomainX,obj.RangeY,x_queries,'linear',nan);
end
end
end
Thank you for all your advice. It helped when discussing this with the author. It's unfortunate that we'll have to redistribute the pcode to other members that are using these methods.