9

I have a DAO interface and implementation of the DAO. The JavaDocs in the interface are what Netbeans displays to the client implementing the DAO methods.

Obviously I will need to maintain the JavaDocs in the interface. But what about the implementation of it? On one hand, it is convenient to have them there, but on the other hand, it is duplication, and requires them to be maintained in two places.

Just wondering what other Java developers do.

EdgeCase
  • 4,719
  • 16
  • 45
  • 73

3 Answers3

9

If the implementing method doesn't provide its own Javadoc, there will still be a link to the interface method's docs. I never understood why Eclipse inserts /* (non-Javadoc) @see ... */ as the Javadocs will automatically reference the interface's docs.

Example:

public interface Named {
  /** Returns the name. */
  public String getName();
}

public class Thing implements Named {
  // note no Javadocs here
  public String getName() {
    return "thing";
  }
}

After running javadoc, Thing.getName's Javadocs are:

getName

public java.lang.String getName()
    Description copied from interface: Named
    Returns the name.
    Specified by:
        getName in interface Named
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
  • 2
    "I never understood why Eclipse inserts" Because then you can simply Cmd+click onto the referenced class and get immediate access to the docs. Not useful for JavaDoc, but useful for development. – mmlac May 13 '14 at 21:44
  • 1
    @mmlac Most IDEs (Eclipse) has a link to go to the defining interface/class – Steve Kuo Mar 15 '16 at 20:21
4

The interface should have all the information about the contract, basically what the method does, the description of parameters, return values and so on.

Unless there's some extra information that isn't clear from the interface description (there rarely is), the implementation documentation should then simply link to the interface method.

This is the format that I've found the most useable from both the implementor and the client side of the fence.

biziclop
  • 48,926
  • 12
  • 77
  • 104
3

In my project, Eclipse automatically creates documentation as below :

     /* (non-Javadoc)
     *  @see com.comp.SomeInterface#method(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
     */
    @Override
    public void method(HttpServletRequest arg0, HttpServletResponse arg1)
            throws Exception {
        // TODO Auto-generated method stub

    }

We have created javadoc using Ant task, so it creates link to the interface.

Nandkumar Tekale
  • 16,024
  • 8
  • 58
  • 85