命名空间命名约定
对于那些编写可重用组件的人来说,如果要扩展 .NET 框架的功能,您认为最佳实践是什么?
例如,我目前正在创建一个 Pop3 库,因为 .NET 中不存在该库。 我是创建自定义命名空间还是使用 System.Net.Mail ?
For those of you out there writing reusable components, what do you consider to be best practice if you're extending the functionality of the .NET framework?
For example, I'm creating a Pop3 library at the moment as one doesn't exist in .NET. Do I create a custom namespace or do I use System.Net.Mail
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自命名空间命名指南:
一般来说,开始将内容包含到框架或库的默认命名空间中是一种非常糟糕的做法。 这可能会导致混淆,新名称空间是否是现有库的一部分,是分发给每个人的框架的一部分,还是由其他人添加的自定义框架的一部分。
此外,命名约定尝试通过使用唯一标识符(例如
CompanyName
)来避免命名空间冲突。 它还减少了新库来源方面的任何混乱和问题。这不仅是微软的事情,Java 中也是如此。 Java 中的命名空间称为“包”,具有以下约定:
所以,如果我有一个超级棒的软件,它可能在
net.coobird.superawesomesoftware
包中。使用包含默认
java.
、javax.
、com.sun.
包的包名称是一个很大的禁忌。From the Namespace Naming Guidelines:
Generally, it's a really bad practice to start including things into the default namespace of a framework or library. This can cause confusion in terms of whether a new namespace is part of the existing library that is part of a framework that is distributed to everyone or is part of a custom framework that was added by someone else.
Also, the naming convention tries to avoid namespace collisions by having unique identifiers such as
CompanyName
. It also reduces any confusion and issues in terms of the source of the new library.This is not only a Microsoft thing but also in Java. Namespaces in Java, called "packages" have the following convention:
So, if I had a super awesome piece of software, it may be in the
net.coobird.superawesomesoftware
package.And using package names that contain the default
java.
,javax.
,com.sun.
packages are a big no-no.另请参阅以下 MSDN 文章,了解有关命名命名空间的指南
Also have a look at following MSDN article for guidelines about naming Namespaces