简体   繁体   English

在抽象方法中编写javadoc的正确方法是什么

[英]What is the correct way to write javadoc in abstract methods

public interface ISomething
    /**
     * This method does something!
     */
    public void something();
}

public abstract class AbstractSomething implements ISomething
{
    /**
     * See {@link #doSomething()}
     */
    public final void something()
    {
        doSomething();
        // Do something else...
        ...
    }

    protected abstract void doSomething();
}

public class ConcreteSomething extends AbstractSomething
{

    /**
     * Concrete implementation of doSomething(). It does... something!
     */
    @Override
    protected void doSomething()
    {
        // Actually do something...
        ...
    }
}

So I have a class hierarchy that looks like this one.所以我有一个看起来像这样的类层次结构。 The idea is to use the public final something() - then abstract - doSomething() pattern so that extending classes would be obligated to call super(), eg Andrzej answer's这个想法是使用 public final something() - 然后抽象 - doSomething() 模式,这样扩展类就必须调用 super(),例如Andrzej 的答案

Then, I will eventually have several implementations that extend AbstractSomething.然后,我最终会有几个扩展 AbstractSomething 的实现。 The clients of this code will then instantiate these implementations and use the ISomething methods.然后,此代码的客户端将实例化这些实现并使用 ISomething 方法。

Something like this:像这样的东西:

public class Main
{
    public static void main(String[] args)
    {
        ConcreteSomething concrete = new ConcreteSomething();
        concrete.something();
    }
}

So the question is, using this design idiom is there a correct way to write a good javadoc for the hierarchy?所以问题是,使用这种设计习惯用法是否有正确的方法来为层次结构编写一个好的 javadoc?

By correct I mean: When clients call concrete.something() I'd want them to see the ConcreteSomething#something() javadoc.正确的意思是:当客户调用crete.something() 时,我希望他们看到ConcreteSomething#something() javadoc。 Since the method is final, however, I can't simply override it and write a concrete javadoc.然而,由于该方法是最终的,我不能简单地覆盖它并编写一个具体的 javadoc。 In addition, my clients won't see the doSomething() method since it's protected so I can't put the concrete javadoc in there too.另外,我的客户不会看到 doSomething() 方法,因为它是受保护的,所以我也不能把具体的 javadoc 放在那里。

So in other words, I probably need the opposite of {@InheritDoc} :)所以换句话说,我可能需要{@InheritDoc}反面:)

Any suggestions?有什么建议?

The problem is similar to an interface's documentation.该问题类似于接口的文档。 Client's will use the abstraction and will mainly see that abstraction's generic documentation.客户将使用抽象并主要看到该抽象的通用文档。 In your case, the best you can do is add the documentation to the constructor of each concrete class.在您的情况下,您能做的最好的事情就是将文档添加到每个具体类的构造函数中。 At least this way the client will see the details of the implementation and you can include relevant @link and @see if needed.至少这样客户端会看到实现的细节,如果需要,你可以包含相关的@link@see

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM