Let we have one abstract class:
classdef ACalculation < handle
methods (Abstract)
[result] = calculate (this, data);
plot (this, data, limX, limY);
end
end
And some other classes that implements ACalculation
classdef Maximum < ACalculation
methods
function [result] = calculate (this, data)
%...
end
function plot (this, data, limX, limY)
%...
end
end
To functions of implementation class i give all needed information, so i don’t need any properties.
So it looks like I need static classes. But if I have static classes I have a problem with calling this functions.
I’d like to do something like that:
criteria = Maximum();
%......
result = criteria.calculate(data);
Is it bad way to use inheritance?
Should I ignore matlab advices to change functions to static?
What else could I do here?
I think that in this case, static interface implementation is quite a good pattern.
Define your classes in the following way:
Then, you can write a function that expects an
ACalculationtype:Then create a
Maximumempty instance and pass it tofoo:If you want to change the calculation method, call
When you say that such a pattern will not work, you are thinking like Java/C#/C++ developer. But unlike in C++ where static and virtual keyword cannot coexist, Matlab has no such limitation, because everything is done at runtime, and an “instance” can be empty or an array of
nelements.