require subclasses to support the same number of input and output arguments as the abstract method of their super class
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
- Concrete subclasses are not required to support the same number of input and output arguments and do not need to use the same argument names. However, subclasses generally use the same signature when implementing their version of the method.
what I want is exactly the opposite, i.e. I want Concrete subclasses are required to support the same number of input and output arguments and otherwise I get an error. How is it possible?
0 Kommentare
Akzeptierte Antwort
Matt J
am 13 Feb. 2022
Bearbeitet: Matt J
am 13 Feb. 2022
In the base class constructor, you can check the function signature, like in this example:
classdef myclass
methods
function obj=myclass()
ml=getfield(metaclass(obj),'MethodList');
meth=ml({ml.Name}=="myMethod");
assert(isequal(numel(meth.InputNames),4) && ...
isequal(numel(meth.OutputNames),2),...
"myMethod has incorrect signature in subclass "+class(obj))
end
end
methods(Abstract)
[out1,out2]=myMethod(obj, in1, in2, in3)
end
end
2 Kommentare
Matt J
am 14 Feb. 2022
You could ask them to implement it, but I doubt it's as easy as that. When the signature contains varargin or varargout, I imagine things get complicated.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Assembly finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!