Java包命名.下划线:特例
作者:互联网
今天,我在一个项目中命名一个程序包,其中包含与称为“访问结构”的概念有关的代码.
现在,将此程序包命名为“ com.myemployer.project.component.accessstructures”似乎很吸引人,并且由于三重“ S”而难以阅读. (较高级别的软件包实际上未命名为“项目”和“组件”).
我很想使用“ … component.access_structures”
我找不到Oracle’s site 上Java约定中提到的任何内容.简短的网络搜索什么都没有.
这样的名字的官方惯例是什么?
解决方法:
Package names are written in all lower case to avoid conflict with the names of classes or interfaces.
Companies use their reversed Internet domain name to begin their package names—for example, com.example.mypackage for a package named mypackage created by a programmer at example.com.
Name collisions that occur within a single company need to be handled by convention within that company, perhaps by including the region or the project name after the company name (for example, com.example.region.mypackage).
In some cases, the internet domain name may not be a valid package name. This can occur if the domain name contains a hyphen or other special character, if the package name begins with a digit or other character that is illegal to use as the beginning of a Java name, or if the package name contains a reserved Java keyword, such as “int”. In this event, the suggested convention is to add an underscore
尽管此文本未指定您的确切情况,但确实表示对于无效的软件包名称,我们应使用下划线.有人可能会说accessStructures是我们如何用Java定义方法并因此命名一个这样的包可能会造成混淆.
总体而言,这完全取决于您.
如果您想遵守这个约定,我相信您应该给您的包裹起个名字:
com.myemployer.project.component.access_structures
您还可以查找同义词并找到可以减少混乱的替代方法.我很快发现了一些:
- accessframework
- accessfactory
- accessarch (accessarchitecture)
- accessconstructs
标签:conventions,naming,package,java 来源: https://codeday.me/bug/20191029/1957921.html