I have some code from a collegue, and I want to add caching to one of the class methods without chancing the original code. I think I should simply overload that function, and call a memoized version of the superclass function. An example:
A.m
classdef A < handle
methods
function res = foo(obj, arg)
disp('class A')
res = arg; % expensive calculation
end
end
end
B.m
classdef B < A
methods
function obj = B()
fn = @foo@A;
obj.foo_m = memoize(fn);
end
function res = foo(obj, arg)
disp('class B')
obj.foo_m(arg)
end
end
end
Now it complains about a an invalid operator in line:
fn = @foo@A;
Furthermore I have the feeling that this might be an issue also: https://stackoverflow.com/a/21413098/1768422
How to solve this in an elegant/transparant way?