Inheriting help documentation from an Abstract base class method
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Matt J
am 17 Feb. 2021
Bearbeitet: Daniel Hediger
am 13 Okt. 2023
Suppose I have a base class with many subclasses, each of which will override an abstract method in the base class,
classdef BaseClass
methods (Abstract)
out=somefunction(in);
end
end
classdef SubClass1<BaseClass
...
end
classdef SubClass2<BaseClass
...
end
...
classdef SubClassN<BaseClass
...
end
The subclasses must all provide non-Abstract implementations of somefunction(). They will all be different implementations, but their input/output syntaxes may all be the same, in which case their help text would all be the same. Is there a way to add a help documentation line in BaseClass.somefunction() that will be 'inherited' by all the sub-classes, so that
>> help SubClass1.somefunction
>> help SubClass2.somefunction
...
>> help SubClassN.somefunction
will all print the same documentation? Naturally, this would be a lot more economical than copying the same help text to all the individual SubClass classdef files.
0 Kommentare
Akzeptierte Antwort
Daniel Hediger
am 13 Okt. 2023
Bearbeitet: Daniel Hediger
am 13 Okt. 2023
Yes, you can add help documentation to the somefunction method in BaseClass so that it's inherited by all the subclasses. Here's how you can do it:
classdef BaseClass
methods (Abstract)
%{
This is the help documentation for somefunction.
You can provide a description here that will be
inherited by all subclasses.
%}
out = somefunction(in);
end
end
By adding comments within the abstract method declaration and description, you can provide documentation that will be inherited by all subclasses. When you use the help command on any subclass's somefunction, it will display the help text from the base class.
For example:
>> help SubClass1.somefunction
This will display the help text you provided in BaseClass.somefunction, which is inherited by SubClass1, SubClass2, and so on.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Construct and Work with Object Arrays 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!