您是否真的将反向域用于Java中的程序包命名? [英] Do you really use your reverse domain for package naming in java?

查看:39
本文介绍了您是否真的将反向域用于Java中的程序包命名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很久以前,我认为在Java中,将您拥有的域用于包命名是很愚蠢和尴尬的.

For a long time ago, I have thought that, in java, reversing the domain you own for package naming is silly and awkward.

您在项目中使用哪个命名包?

Which do you use for package naming in your projects?

推荐答案

一旦您了解了该惯例的存在,它就至少不会让人感到愚蠢或尴尬.

Once you understand why the convention exists, it shouldn't feel silly or awkward in the least.

此方案有两件重要的事情:

This scheme does two important things:

  • 所有代码都包含在其他任何人都不会与之碰撞的软件包中.您拥有您的域名,因此是孤立的.如果我们没有这个约定,那么许多公司将有一个实用程序"包,其中包含"StringUtil","MessageUtil"等类.如果您尝试使用任何其他人的代码,这些包将很快冲突.

  • All of your code is contained in packages that noone else will collide with. You own your domain name, so it's isolated. If we didn't have this convention, many companies would have a "utilities" package, containing classes like "StringUtil", "MessageUtil" etc. These would quickly collide if you tried to use anyone else's code.

它的反向"性质使类目录的布局在顶层非常狭窄.如果展开广口瓶,则会看到"com","org","net"等目录,然后在每个组织/公司名称下.

The "reverse" nature of it makes class-directory layout very narrow at the top level. If you expand a jar, you'll see "com", "org", "net" etc dirs, then under each of those the organization/company name.

我们通常不扩展jar,但是在早期的Java开发中,这很重要,因为人们对applet使用了扩展的dir结构.

We usually don't expand jars, but in early java development, this was important because people used expanded dir structures for applets.

但是,这很好,因为源代码目录结构具有非常自上而下"的感觉.您从最一般的(com,org,net ...)到较不普遍的(公司名称)再到更具体的(项目/产品/库名称)

However, this is nice now as source code dir structures have a very "top-down" feel. You go from most general (com, org, net...) to less general (company name) to more specific (project/product/lib name)

这篇关于您是否真的将反向域用于Java中的程序包命名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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