I am building a CMS and the naming convention for classes has been debated between the other developer involved and myself. The problem arises specifically with "Page", as it is a public class available in a typical library.
我正在构建一个CMS,并且在我和其他开发人员之间讨论了类的命名约定。问题出现在“Page”中,因为它是典型库中的公共类。
A natural response would be to call it MVCMSPage (where MVCMS is the to-be name of the cms) or to rely on referencing the class through the dll (can't think of the term atm..) but both seem to have a hint of codesmell to them.
一个自然的反应是将它称为MVCMSPage(其中MVCMS是cms的名称)或依赖于通过dll引用类(不能想到术语atm ..)但两者似乎都有代码的暗示给他们。
What would you advise?
你有什么建议吗?
Thanks
5 个解决方案
#1
I'd go with something other than 'Page
'. The 'Page
' class that is built into .NET is a very generic class that is commonly known as part of ASP.NET. You could easily confuse other developers (or even yourself, a few months down the road if you don't look at it for a while).
我会选择“页面”之外的东西。构建在.NET中的“Page”类是一个非常通用的类,通常称为ASP.NET的一部分。您可能很容易混淆其他开发人员(或者甚至是您自己,如果您暂时不看它几个月)。
I usually go with a naming convention such as:
我通常使用命名约定,例如:
ApplicationName + "Page"
I also like to follow the MS .NET naming guidelines of only capitalizing the first letter of an acronym longer than 2 characters. Since 'MVCMS
' can be confused for the 'MVC' architecture style if read incorrectly, I wouldn't use 'MvcmsPage
' or 'MVCmsPage
', I'd call it something like this:
我还想遵循MS .NET命名准则,只使用长度超过2个字符的首字母缩写词的第一个字母。由于'MVCMS'可能会被混淆为'MVC'架构风格,如果读取不正确,我不会使用'MvcmsPage'或'MVCmsPage',我称之为:
MvCmsPage
This is descriptive and fairly easy to read and understand.
这是描述性的,相当容易阅读和理解。
Of course it's really up to you. Mainly it's a matter of preference. Just don't use 'Page
' as it will make some developers angry (such as myself).
当然,这取决于你。主要是偏好问题。只是不要使用'Page'因为它会让一些开发人员生气(比如我自己)。
#2
I think the term you were looking for is namespace
.
我认为你要找的术语是名称空间。
I don't think I would rely on namespace differentiation for such a fundamental class in the System.Web space. If you were writing a console-based notification mechanism then it might be ok, but since you're working in the web arena, I'd avoid it. My vote would be to use the namespace as the main differentiator and name it something simple, like ContentPage
so you would have something like MvcCms.Web.ContentPage
as the full name of the class.
我不认为我会依赖于System.Web空间中这样一个基础类的命名空间区分。如果您正在编写基于控制台的通知机制,那么它可能没问题,但由于您在Web领域工作,我会避免它。我的投票将是使用命名空间作为主要区别,并将其命名为简单的内容,例如ContentPage,因此您将拥有类似MvcCms.Web.ContentPage的类作为类的全名。
If you do it this way you can import both your namespace and System.Web
and still be able to differentiate the classes AND you have a short name that makes sense and isn't cumbersome to use or reference (when speaking about it).
如果你这样做,你可以导入你的命名空间和System.Web,并且仍然能够区分类和你有一个有意义的简短名称,并且使用或引用(在谈论它时)并不麻烦。
#3
To me, since you're developing a CMS, the object at the root is the Content. So either MvCmsContent, CmsContent, or just Content would seem fine to me. Isn't naming always the hardest part of a project?
对我而言,由于您正在开发CMS,因此根目录中的对象是内容。所以MvCmsContent,CmsContent或者只是内容对我来说似乎都很好。不是命名总是项目中最难的部分吗?
#4
We had a similar issue and just went with CMSPage. It's a bit less cumbersome than the MVCMSPage, but still obviously CMS and you can further extend that class for multiple systems in the future if need be.
我们遇到了类似的问题,只是选择了CMSPage。它比MVCMSPage稍微麻烦一点,但显然仍然是CMS,如果需要,您可以在将来进一步扩展该类用于多个系统。
#5
I'm thinking the "page" you're referring as the application's equivalent of a database record. As others are saying this it's a rather loaded term. Here's a few random ideas:
我认为你所指的“页面”是应用程序等同于数据库记录。正如其他人所说,这是一个相当负荷的术语。这里有一些随意的想法:
- Node
- View
- PageRecord
- CmsPage
- WebDocument
- ContentPage
Your choice should try to convey the essence of the object type. I'd avoid putting the product name into the class name. I prefer namespaces for that.
您的选择应该尝试传达对象类型的本质。我会避免将产品名称放入类名中。我更喜欢名称空间。
#1
I'd go with something other than 'Page
'. The 'Page
' class that is built into .NET is a very generic class that is commonly known as part of ASP.NET. You could easily confuse other developers (or even yourself, a few months down the road if you don't look at it for a while).
我会选择“页面”之外的东西。构建在.NET中的“Page”类是一个非常通用的类,通常称为ASP.NET的一部分。您可能很容易混淆其他开发人员(或者甚至是您自己,如果您暂时不看它几个月)。
I usually go with a naming convention such as:
我通常使用命名约定,例如:
ApplicationName + "Page"
I also like to follow the MS .NET naming guidelines of only capitalizing the first letter of an acronym longer than 2 characters. Since 'MVCMS
' can be confused for the 'MVC' architecture style if read incorrectly, I wouldn't use 'MvcmsPage
' or 'MVCmsPage
', I'd call it something like this:
我还想遵循MS .NET命名准则,只使用长度超过2个字符的首字母缩写词的第一个字母。由于'MVCMS'可能会被混淆为'MVC'架构风格,如果读取不正确,我不会使用'MvcmsPage'或'MVCmsPage',我称之为:
MvCmsPage
This is descriptive and fairly easy to read and understand.
这是描述性的,相当容易阅读和理解。
Of course it's really up to you. Mainly it's a matter of preference. Just don't use 'Page
' as it will make some developers angry (such as myself).
当然,这取决于你。主要是偏好问题。只是不要使用'Page'因为它会让一些开发人员生气(比如我自己)。
#2
I think the term you were looking for is namespace
.
我认为你要找的术语是名称空间。
I don't think I would rely on namespace differentiation for such a fundamental class in the System.Web space. If you were writing a console-based notification mechanism then it might be ok, but since you're working in the web arena, I'd avoid it. My vote would be to use the namespace as the main differentiator and name it something simple, like ContentPage
so you would have something like MvcCms.Web.ContentPage
as the full name of the class.
我不认为我会依赖于System.Web空间中这样一个基础类的命名空间区分。如果您正在编写基于控制台的通知机制,那么它可能没问题,但由于您在Web领域工作,我会避免它。我的投票将是使用命名空间作为主要区别,并将其命名为简单的内容,例如ContentPage,因此您将拥有类似MvcCms.Web.ContentPage的类作为类的全名。
If you do it this way you can import both your namespace and System.Web
and still be able to differentiate the classes AND you have a short name that makes sense and isn't cumbersome to use or reference (when speaking about it).
如果你这样做,你可以导入你的命名空间和System.Web,并且仍然能够区分类和你有一个有意义的简短名称,并且使用或引用(在谈论它时)并不麻烦。
#3
To me, since you're developing a CMS, the object at the root is the Content. So either MvCmsContent, CmsContent, or just Content would seem fine to me. Isn't naming always the hardest part of a project?
对我而言,由于您正在开发CMS,因此根目录中的对象是内容。所以MvCmsContent,CmsContent或者只是内容对我来说似乎都很好。不是命名总是项目中最难的部分吗?
#4
We had a similar issue and just went with CMSPage. It's a bit less cumbersome than the MVCMSPage, but still obviously CMS and you can further extend that class for multiple systems in the future if need be.
我们遇到了类似的问题,只是选择了CMSPage。它比MVCMSPage稍微麻烦一点,但显然仍然是CMS,如果需要,您可以在将来进一步扩展该类用于多个系统。
#5
I'm thinking the "page" you're referring as the application's equivalent of a database record. As others are saying this it's a rather loaded term. Here's a few random ideas:
我认为你所指的“页面”是应用程序等同于数据库记录。正如其他人所说,这是一个相当负荷的术语。这里有一些随意的想法:
- Node
- View
- PageRecord
- CmsPage
- WebDocument
- ContentPage
Your choice should try to convey the essence of the object type. I'd avoid putting the product name into the class name. I prefer namespaces for that.
您的选择应该尝试传达对象类型的本质。我会避免将产品名称放入类名中。我更喜欢名称空间。