Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I inherit documentation from super classes in Matlab?

I have a Super class that I've done some extensive documentation on. There are subclasses that inherit from this super class and I would like to reuse the documentation of the super if possible. For example with Super class ClassA:

classdef ClassA
    %CLASSA Super Class for all others classes
    %
    % CLASSA Properties:
    %   Prop1       It's the first property
    %   Prop2       It's the second
    %
    % CLASSA Methods:
    %   Method1     It's a method
    %   Method2     It's another method

    function value = Method1(var)
        % Super implementation of Method1
    end

    % Other method definitions follow
end

And a subclass, ClassB:

classdef ClassB < ClassA
    %CLASSB Subclass of super class CLASSA
    %
    % CLASSB Properties:
    %   Prop3       It's the first property of subclass
    %   
    % CLASSB Methods:
    %   Method 3    It's 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 only get ClassB's help description. I want to have the Super's help description to also be included. The output would look something like this:

 CLASSB Subclass of super class CLASSA

 CLASSB Properties:
    Prop1       It's the first property
    Prop2       It's the second
    Prop3       It's the first property of subclass

 CLASSB Methods:
    Method1     It's a method
    Method2     It's another method
    Method3     It's the first method of subclass

Is there a way to do this?

like image 295
James Mertz Avatar asked May 07 '13 15:05

James Mertz


People also ask

What methods does a subclass inherit from its superclass?

A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses, but the constructor of the superclass can be invoked from the subclass.

Can a class inherit from multiple classes MATLAB?

When you create a subclass derived from multiple superclasses, the subclass inherits the properties, methods, and events defined by all specified superclasses. If more than one superclass defines a property, method, or event having the same name, there must be an unambiguous resolution to the multiple definitions.

Does MATLAB have inheritance?

Implementation and Interface InheritanceMATLAB classes support both the inheritance of implemented methods from a superclass and the inheritance of interfaces defined by abstract methods in the superclass.

What are Superclasses in MATLAB?

superclasses( obj ) displays the names of all visible superclasses of object obj , where obj is an instance of a MATLAB class. obj can be either a scalar object or an array of objects. example. s = superclasses(___) returns the superclass names in a cell array of character vectors.


1 Answers

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

For example:

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 could say:

help_super

You get nicely formatted hyperlinks.

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

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

web

Note that inherited properties/methods are displayed.

like image 152
Amro Avatar answered Nov 25 '22 04:11

Amro