namespace naming conventions(命名空间命名约定)
问题描述
对于那些编写可重用组件的人,如果您要扩展 .NET 框架的功能,您认为最佳实践是什么?
例如,我目前正在创建一个 Pop3 库,因为 .NET 中不存在该库.我是创建自定义命名空间还是使用 System.Net.Mail
?
来自 命名空间命名指南:
<块引用>命名空间的一般规则是使用公司名称后跟技术名称和可选的特点和设计如下.复制代码
CompanyName.TechnologyName[.Feature][.Design]
通常,开始将内容包含到框架或库的默认命名空间中是一种非常糟糕的做法.这可能会导致混淆,即新命名空间是现有库的一部分,而现有库是分发给所有人的框架的一部分,还是属于其他人添加的自定义框架的一部分.
此外,命名约定尝试通过具有唯一标识符(例如 CompanyName
)来避免命名空间冲突.它还减少了新库的来源方面的任何混淆和问题.
这不仅是微软的事情,Java 也是如此.Java 中称为包"的命名空间具有以下约定:p><块引用>
唯一包名的前缀是始终以全小写 ASCII 书写字母,应该是其中之一顶级域名,目前为com,edu、gov、mil、net、org 或其中之一英文两字母代码识别ISO 标准中指定的国家3166, 1981.
包的后续组件名称因人而异组织自己的内部命名公约.这样的约定可能指定某个目录名称组成部分是部门,部门,项目、机器或登录名.
所以,如果我有一个超级棒的软件,它可能在 net.coobird.superawesomesoftware
包中.
并且使用包含默认 java.
、javax.
、com.sun.
包的包名是一个很大的禁忌.
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
?
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. Copy Code
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 in the Java as well. Namespaces in Java, called "packages" has 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.
这篇关于命名空间命名约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:命名空间命名约定
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- SSE 浮点算术是否可重现? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01