2013-05-07 2 views
6

저는 몇 가지 광범위한 문서 작업을 수행 한 수퍼 클래스를 보유하고 있습니다. 이 수퍼 클래스에서 상속받은 하위 클래스가 있으며 가능한 경우 수퍼 문서를 다시 사용하고 싶습니다.Matlab의 수퍼 클래스에서 문서를 상속하는 방법은 무엇입니까?

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 

그리고 서브 클래스, ClassB가 : 슈퍼 클래스 ClassA와 예를 들어

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 

내가 help ClassB를 입력하면 난 단지 ClassB의 도움말 설명을 얻을. 나는 슈퍼의 도움말 설명도 포함 시키길 원합니다. 출력은 다음과 같습니다.

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 

이 방법이 있습니까?

+5

나는 이것을 할 수 있다고 생각지 않는다. 그러나 수퍼 클래스에 자동으로 연결되는 "보기"도 포함시킬 수 있습니다. 'ClassB' 문서의 끝 부분에'See also CLASSA'를 넣으면 나머지는 MATLAB이 처리합니다. – wakjah

+0

나는 이것에 대해 몰랐다. 그건 아주 영리합니다. – KronoS

답변

5

@SamRoberts으로 표시된 바와 같이, 특성 및 방법을 문서화하는 standard way이 있습니다. 예를 들어

:

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 

지금 명령 행에서

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 

, 당신은 말할 수 :

당신은 잘 하이퍼 링크 형식 얻을.

doc Derived (또는 단어를 강조 표시하고 F1을 누르면 알 수 있습니다. 내부적으로 help2html을 호출하여 도움말을 HTML로 변환합니다. 예를 들어, 우리는이에게 자신을 할 수있는 : 속성을 상속

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

web

주/방법이 표시됩니다.

+0

사실, 한 번'handle' 클래스에서 상속받을 때 특히'doc' /'help2html'의 이런 동작이 바람직하지 않습니다. 이 기능을 끄기 위해 내부 MALTAB 함수를 편집해야했습니다 :'[toolboxdir ('matlab') '/helptools/private/help2xml.m]] : http://pastebin.com/AYMa2p5q – Amro

+2

- 내부 함수를 수정하는 대신, 나는 보통 자신의 클래스 인'HandleHiddenMethods'를 상속받습니다. 이것은'handle'을 상속 받고, 하나의'methods (Hidden = true)'블록으로 구성됩니다. 여기에는'handle'의 모든 메소드의 복사본이 있습니다. 오버로드되어 호출을 바로 handle에 전달합니다. 그래서'HandleHiddenMethods'는'handle'과 똑같이 동작하지만, 자동 생성 된 문서에는 그 메소드를 표시하지 않습니다. 이것은'isvalid'가 아닌 Sealed이고 오버로드 할 수없는 모든 메소드에서 작동합니다. –

+0

@SamRoberts :이 팁을 공유해 주셔서 감사합니다. 이러한 수정 사항을 추적하는 것은 쉽지 않습니다. 특히 MATLAB을 새로 릴리스 할 때마다 업그레이드하는 것이 좋습니다. – Amro

2

당신이 설명하는 방식으로 문서를 작성하는 경우 사용자가 원하는 것을 얻을 수있는 유일한 방법은 help에 과부하를 지정하여 사용자 지정 작업을 수행하는 것입니다. 예를 들어 오버로드 된 helpbuiltin('help') 그 자체를 호출 한 다음 수퍼 클래스의 builtin('help')을 호출 할 수 있습니다.

그러나 표준 방식으로 문서화하지는 않습니다. 일반적으로 속성 바로 위에 주석을 사용하여 속성을 문서화하고 메서드의 함수 시그니처 바로 아래에 주석이있는 메서드를 문서화합니다. 그렇게하면 모든 상속 된 메소드에 대한 도움말이 자동으로 표시됩니다.

+0

기존의 문서 작성 방법에 대한 링크가 있습니까? 나는 [여기에 개략적으로 제시된] 제안 (http://www.mathworks.com/help/matlab/matlab_prog/create-help-for-classes.html)을 따랐다. – KronoS

+0

@ Amro의 대답을 참조하십시오. –