代码注释:您是否将代码注释放在接口或具体类上,或同时放在两者上? [英] Code Commenting: Do you put your code comments on Interfaces or on Concrete classes, or both?

查看:84
本文介绍了代码注释:您是否将代码注释放在接口或具体类上,或同时放在两者上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

记录类和接口的最佳实践是什么.假设您有一个名为Foo的具体类,它是从一个名为IFoo的接口派生的.您在哪里对方法发表意见?您是否在Interface以及具体的类上重复了您的评论?

What is the best practice in documenting classes and interfaces. Say if you have a concrete class called Foo, that derives from an interface called IFoo. Where do you put your comments for your methods? Do you duplicate your comments on the Interface as well as the concrete class?

以下是重复注释的示例:

Here is an example where comments are duplicated:

public class Foo : IFoo
{
    /// <summary>
    /// This function does something
    /// </summary>        
    public void DoSomething()
    {
    }
}

public interface IFoo
{
    /// <summary>
    /// This function does something
    /// </summary>        
    void DoSomething();
}

推荐答案

我会在两者上都发表评论.

I would put comments on both.

在界面上,我将对界面成员和用途背后的意图进行评论.

On interfaces I would comment on the intent behind the interface members and usage.

在实现上,我将对具体实现的原因进行评论.

On implementations I would comment on the reasons for the specific implementation.

这篇关于代码注释:您是否将代码注释放在接口或具体类上,或同时放在两者上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆