C#类的命名约定:它是BaseClass的或ClassBase或抽象类 [英] C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass
问题描述
什么是推荐的方式来命名基类?它是$ 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屋!