How do I inherit documentation from superclasses in Matlab?

I have a Super class over which I have done extensive documentation. There are subclasses that inherit from this superclass, and I would like to reuse the documentation super if possible. For example, with Super class ClassA :

 classdef ClassA %CLASSA Super Class for all others classes % % CLASSA Properties: % Prop1 It the first property % Prop2 It the second % % CLASSA Methods: % Method1 It a method % Method2 It another method function value = Method1(var) % Super implementation of Method1 end % Other method definitions follow end 

And a subclass of ClassB:

 classdef ClassB < ClassA %CLASSB Subclass of super class CLASSA % % CLASSB Properties: % Prop3 It the first property of subclass % % CLASSB Methods: % Method 3 It the first method of subclass function value = Method1(var) % Subclass implementation of Method1 end % Other method definitions follow end 

If I type help ClassB , I get only the ClassB help description. I want to include a description of Super help. The result will look something like this:

  CLASSB Subclass of super class CLASSA CLASSB Properties: Prop1 It the first property Prop2 It the second Prop3 It the first property of subclass CLASSB Methods: Method1 It a method Method2 It another method Method3 It the first method of subclass 

Is there any way to do this?

+6
source share
2 answers

As @SamRoberts noted, there is a standard standard way of documenting properties and methods.

For instance:

 classdef Super %Super Summary of this class goes here % Detailed explanation goes here % % Super Properties: % One - Description of One % Two - Description of Two % % Super Methods: % myMethod - Description of myMethod % properties One % First public property Two % Second public property end properties (Access=private) Three % Do not show this property end methods function obj = Super % Summary of constructor end function myMethod(obj) % Summary of myMethod disp(obj) end end methods (Static) function myStaticMethod % Summary of myStaticMethod end end end 

and

 classdef Derived < Super %Derived Summary of this class goes here % Detailed explanation goes here % % See also: Super properties Forth % Forth public property end methods function obj = Derived % Summary of constructor end function myOtherMethod(obj) % Summary of myMethod disp(obj) end end end 

Now on the command line you can say:

help_super

You get beautifully formatted hyperlinks.

Also note what you get with doc Derived (or when you highlight a word and press F1 ). This internally calls help2html to convert the help to HTML. For example, we could do it ourselves:

 >> %doc Derived >> web(['text://' help2html('Derived')], '-noaddressbox', '-new') 

web

Note that inherited properties / methods are displayed.

+5
source

If you write the documentation as you describe, I think the only way to get what you ask is to overload help to do something customized. For example, your overloaded help can call builtin('help') on its own, and then builtin('help') on its superclass.

However, you are not documenting things in a standard way; as a rule, you will document properties using comments directly above the property itself, as well as document methods with comments directly below the signature of the method function. If you do this, you will automatically display help for all inherited methods.

+2
source

Source: https://habr.com/ru/post/944455/


All Articles