C#类的命名约定:它是BaseClass的或ClassBase或抽象类 [英] C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass

查看:2540
本文介绍了C#类的命名约定:它是BaseClass的或ClassBase或抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是推荐的方式来命名基类?它是$ P $与pfixing类型名基本摘要或将我们刚刚与基地后缀呢?

考虑以下几点:

类型:视图模型例如的 MainViewModel ReportViewModel

的基类: BaseViewModel ViewModelBase AbstractViewModel

还认为:

类型:产品例如的 VirtualProduct ExpiringProduct

的基类: BaseProduct ProductBase AbstractProduct

你认为哪是更标准?

 实体类:EntityBase
{
}

 实体类:BaseEntity
{
}


解决方案

有与基本后缀,例如框架示例 System.Configuration.Provider.ProviderBase System.Web.SessionState.SessionStateStoreProviderBase

但绝不是在框架中所有抽象基类遵循这个惯例(如 System.Data.Common.DbParameter System.Data这。 Common.DbCommand )。

我个人避免使用后缀的除非的我想强调一个事实,即它是一个抽象类,并认为否则类的用户所期望的名称来表示一个具体的实现。

What is the recommended approach to naming base classes? Is it prefixing the type name with "Base" or "Abstract" or would we just suffix it with "Base"?

Consider the following:

type: ViewModel e.g. MainViewModel, ReportViewModel

base class: BaseViewModel or ViewModelBase or AbstractViewModel

Also consider:

type: Product e.g. VirtualProduct, ExpiringProduct

base class: BaseProduct or ProductBase or AbstractProduct

Which do you think is more standard?

class Entity : EntityBase
{
}

or

class Entity : BaseEntity
{
}

解决方案

There are examples in the Framework with the Base suffix, e.g. System.Configuration.Provider.ProviderBase, System.Web.SessionState.SessionStateStoreProviderBase.

But by no means all abstract base classes in the Framework follow this convention (e.g. System.Data.Common.DbParameter, System.Data.Common.DbCommand).

Personally I would avoid using the suffix unless I wanted to emphasize the fact that it's an abstract class and felt that otherwise users of the class might expect the name to indicate a concrete implementation.

这篇关于C#类的命名约定:它是BaseClass的或ClassBase或抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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