C# Class naming convention: Is it BaseClass or ClassBase or AbstractClass

前端 未结 8 1119
时光取名叫无心
时光取名叫无心 2020-12-07 14:22

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

相关标签:
8条回答
  • 2020-12-07 14:49

    We use BaseEntity, but I think it your own preference. I frequently see the other.

    Just be consistent within your context, be that your project, namespace or if possible, your team. Different conventions are worse than a bad convention IMHO.

    0 讨论(0)
  • 2020-12-07 14:53

    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.

    0 讨论(0)
  • 2020-12-07 14:57

    If you're talking about virtual base classes, Microsoft's standard is ClassnameBase (like CollectionBase.)

    0 讨论(0)
  • 2020-12-07 15:04

    None of the above. Consider what purpose your base class provides; name it that. For example, the base class of Automobile and Bicycle could be Vehicle.

    If you're creating base classes just to have a base class of one class, and with no purpose or reason other than that, you're probably doing something wrong.

    0 讨论(0)
  • 2020-12-07 15:04

    Always think about alphabetizing when you name stuff. I really don't like looking at a SQL server and every stored procedure is named usp[something]. Along the same lines, don't overuse Get and Set as leading names for a function. Instead of GetItems or PlaceOrder, think about naming them as ItemsGet or OrderPlace.

    So, in general, ClassnameBase / EntityBase would be a better choice.

    0 讨论(0)
  • 2020-12-07 15:05

    BaseEntity looks a lot like camel case - strName, bseEntity. I'd go for EntityBase since it defines the subject first, which will help you identify it's function quicker.

    0 讨论(0)
提交回复
热议问题