良好的命名空间命名约定 [英] Good Namespace Naming Conventions

查看:174
本文介绍了良好的命名空间命名约定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为CRUD业务应用程序创建一个类库.业务对象(以及相关的数据访问层对象)的主要类别"是:

I am creating a class library for a CRUD business application. The major "categories" of business objects (with related data access layer objects) are:

  • 维护(与大师一起工作 数据库中的表格(主列表)
  • 事件(大多数对象与现实世界中的事件有关)
  • 搜索(显而易见)
  • Maintenance (for working with master tables (master lists) in the database
  • Incidents (most objects relate to a real-world incident)
  • Search (obvious)

到目前为止,我的命名空间设置如下:

As of now, my namespaces are set up as follows:

  • BusinessObjects.Maintenance.Contacts
  • BusinessObjects.Maintenance.Products
  • BusinessObjects.Maintenance.Classifications
  • .
  • BusinessObjects.Incidents.Contacts
  • BusinessObjects.Incidents.Products
  • BusinessObjects.Incidents.Classifications
  • .
  • BusinessObjects.Search.Contacts
  • BusinessObjects.Search.Products
  • BusinessObjects.Search.Classifications
  • .
  • Dal.Maintenance.Contacts
  • Dal.Maintenance.Products
  • Dal.Maintenance.Classifications
  • .
  • 达因事件联系方式
  • 事件事件产品
  • 事件事件分类
  • .
  • Dal.Search.Contacts
  • Dal.Search.Products
  • BusinessObjects.Maintenance.Contacts
  • BusinessObjects.Maintenance.Products
  • BusinessObjects.Maintenance.Classifications
  • .
  • BusinessObjects.Incidents.Contacts
  • BusinessObjects.Incidents.Products
  • BusinessObjects.Incidents.Classifications
  • .
  • BusinessObjects.Search.Contacts
  • BusinessObjects.Search.Products
  • BusinessObjects.Search.Classifications
  • .
  • Dal.Maintenance.Contacts
  • Dal.Maintenance.Products
  • Dal.Maintenance.Classifications
  • .
  • Dal.Incidents.Contacts
  • Dal.Incidents.Products
  • Dal.Incidents.Classifications
  • .
  • Dal.Search.Contacts
  • Dal.Search.Products

请注意,每个类都以相同的名称结尾.

Notice that every class ends up with the same name.

这是好表格吗?

此命名空间约定会引起任何问题吗?与寻找/使用此代码的其他人是否有混淆?

我确实意识到在表单代码中,一个缺点是我将必须使用命名空间来限定所有对象.对我来说,这没什么大不了的.如果那是一个词,我通常更喜欢露骨.

I do realize that in the form code, one drawback will be that I will have to qualify all objects with the namespace. To me, that isn't a big deal. I usually prefer a little explicit-ity, if that's a word.

推荐答案

无论如何我还是觉得不错.但是,我会避免使用缩写词,否则会造成混淆,并迫使人们不得不知道缩写词或查找缩写词.而且它们变得不可读和难以言说.

It seems Ok to me anyway. I would stay away from abbreviations though, that would get confusing and force people to have to know the abbreviations or look them up. Also they become unreadable and unspeakable.

"Lets take a look at the BusObjConfIntContYYYYmmdd package now..."

您可能会遇到的一个问题是名称之间的细微差别.由于名称的长度是一个可能的问题,您的眼睛可能会遮盖整个事物,而只吸收其中的一部分.会不会发生这种情况?:

One issue you might run into is names with subtle differences. With length of names being a possible issue, your eyes might gloss over the whole thing and pick up only part of it. Would there ever be a case where this happened?:

BusinessObjects.Incidents.Classifications
BusinessObjects.Classifications.Incidents

BusinessObjects.Forms.ProjectManager.Exportable.Windows.XP
BusinessObjects.Forms.ProductManager.Exportable.Windows.XP

这个人为的例子可能会成为问题.

That contrived example might become a problem.

这篇关于良好的命名空间命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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