命名空间命名约定

发布于 2024-07-22 00:38:17 字数 133 浏览 3 评论 0原文

对于那些编写可重用组件的人来说,如果要扩展 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

也只是曾经 2024-07-29 00:38:17

来自命名空间命名指南

命名空间命名的一般规则
是使用公司名称后跟
技术名称和可选的
功能和设计如下。

公司名称.技术名称[.功能][.设计]

一般来说,开始将内容包含到框架或库的默认命名空间中是一种非常糟糕的做法。 这可能会导致混淆,新名称空间是否是现有库的一部分,是分发给每个人的框架的一部分,还是由其他人添加的自定义框架的一部分。

此外,命名约定尝试通过使用唯一标识符(例如 CompanyName)来避免命名空间冲突。 它还减少了新库来源方面的任何混乱和问题。

这不仅是微软的事情,Java 中也是如此。 Java 中的命名空间称为“包”,具有以下约定

唯一包名的前缀是
始终以全小写 ASCII 书写
字母并且应该是其中之一
顶级域名,目前为com,
edu、gov、mil、net、org 或其中之一
英文两字母代码识别
ISO 标准指定的国家
3166, 1981.

包的后续组件
名称根据
组织自己的内部命名
惯例。 此类约定可能
指定某个目录名称
组成部分是部门、部门、
项目、机器或登录名。

所以,如果我有一个超级棒的软件,它可能在 net.coobird.superawesomesoftware 包中。

使用包含默认 java.javax.com.sun. 包的包名称是一个很大的禁忌。

From the Namespace Naming Guidelines:

The general rule for naming namespaces
is to use the company name followed by
the technology name and optionally the
feature and design as follows.

CompanyName.TechnologyName[.Feature][.Design]

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:

The prefix of a unique package name is
always written in all-lowercase ASCII
letters and should be one of the
top-level domain names, currently com,
edu, gov, mil, net, org, or one of the
English two-letter codes identifying
countries as specified in ISO Standard
3166, 1981.

Subsequent components of the package
name vary according to an
organization's own internal naming
conventions. Such conventions might
specify that certain directory name
components be division, department,
project, machine, or login names.

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.

栀梦 2024-07-29 00:38:17

另请参阅以下 MSDN 文章,了解有关命名命名空间的指南

命名空间的名称

为命名空间选择的名称应表明其功能
通过命名空间中的类型可用。 例如,
System.Net.Sockets 命名空间包含使开发人员能够
使用套接字通过网络进行通信。

命名空间名称的一般格式如下:

<公司>.(<产品>|<技术>)[.<功能>][.<子命名空间>]

例如,Microsoft.WindowsMo​​bile.DirectX

Also have a look at following MSDN article for guidelines about naming Namespaces

Names of Namespaces

The name chosen for a namespace should indicate the functionality made
available by types in the namespace. For example, the
System.Net.Sockets namespace contains types that enable developers to
use sockets to communicate over networks.

The general format for a namespace name is as follows:

<Company>.(<Product>|<Technology>)[.<Feature>][.<Subnamespace>]

For example, Microsoft.WindowsMobile.DirectX.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文