“深度子域”的包命名组织
在滚动 Java 代码时,我始终坚持推荐约定 <反向域名>.<内部命名约定>
。通常,这是非常可靠的,可以防止任何命名冲突的问题。然而,当您与“深度子域”组织打交道时 - 例如 cisb.justice.qld.gov.au
- 它就有点过头了。特别是当您添加内部约定并最终得到诸如 au.gov.qld.justice.cisb.comm.sony.pfm42v1.
等内容时。
现在我假设我不是唯一的为昆士兰州政府工作的程序员,与司法部同上,因此简化为 au.gov.qld.
和 au.gov.qld.justice.
已不再适用。
其他人在类似情况下使用过哪些约定?
When rolling java code I've always stuck to the recommended convention of <reversed domain name>.<internal naming convention>
. Usually this is pretty solid and prevents any issues with naming conflicts down the line. However, when you're dealing with 'deeply sub-domained' organisations - for example cisb.justice.qld.gov.au
- it gets a bit over the top. especially when you add the internal conventions and end up with something like au.gov.qld.justice.cisb.comm.sony.pfm42v1.
etc.
Now I'm assuming that I'm not the only programmer working for the Queensland Government, ditto with the Department of Justice so simplifying to au.gov.qld.
and au.gov.qld.justice.
are out.
What are some of the conventions others have used in similar situations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
采取的方法是利用
au.gov.qld.justice.duet.
作为基础包。这遵循 java 标准并引用项目名称而不是内部部门名称,以防止将来出现任何部门名称洗牌问题。The approach taken was to utilize
au.gov.qld.justice.duet.
as the base package. This adheres to the java standards and references a project name rather than internal department name to prevent any issues with department name shuffles in the future.嗯,是的,显然
au.gov.justice
已经过时了,因为它不是您域名的一部分。au.gov.justice
指的是联邦政府,而不是州政府。如果显而易见的选择对您来说太长,请考虑
justice.qld.gov.au
或courts.qld.gov.au
。这是否可以取决于该部门有多少人工作、其结构如何以及是否有任何策略,但它可能是可以接受的,因为您仍然拥有项目名称来使包名称唯一。
这是您部门第一次出现这个问题吗?也许其他人已经选择了一个约定。
政府部门的另一个问题是它们经常更名。
你们部门刚刚改名了吗?也许您应该坚持使用旧名称,或者选择下次名称更改时可能仍然有效的名称。
Java 语言规范 提醒我们,主要的命名空间的目的是确保包名称是唯一的,因此,如果您以
au.gov.qld
开头包名称,那么您可能会有一点灵活性,只要您采取措施确保名称不重复不与其他政府部门发生冲突。Well, yes, obviously
au.gov.justice
is out, because that's not part of your domain name backwards.au.gov.justice
would mean Federal Government, not State.If the obvious choice is too long for you, consider
justice.qld.gov.au
orcourts.qld.gov.au
.Whether that's OK will depend on how many other people work for the department, how it's structured, and if there are any policies, but it might be acceptable because you still have the project name to make the package name unique.
Is this the first time this issue has popped up in your department? Maybe somebody else already picked a convention.
Another issue for government departments is that they frequently change names.
Did your department just change names? Maybe you should stick with the old name, or pick something that's likely to still work the next time the name changes.
The Java Language Specification reminds us that the primary purpose of namespaces is to ensure the package name is unique, so provided you start the package name with
au.gov.qld
, you might have a small amount of flexibility provided you take steps to ensure the name doesn't clash with another government department.我还没有听说过任何处理这个问题的通用惯例。
如果这是一个真正的问题,那么您需要与昆士兰司法部的其他开发人员交谈,以找出公司特定的约定。
公司信息系统部门 (?) 不是为昆士兰司法部制定 IT 政策吗?你就不能跟政策负责人说句话,让他发一份备忘录吗? (是的,我知道......生活从来没有那么简单......但可能值得一试。)
但坦率地说,
cisb.justice.qld.gov.au
并不是“超越”顶部”。I've not heard of any general conventions to deal with this.
If it is a real issue, then you need to talk to other developers within Queensland Justice to figure out a corporate specific convention.
Doesn't Corporate Information Systems Branch (?) set IT policy for Queensland Justice? Can't you just have a word to the policy dude and get him to send out a memo? (Yeah, I know ... life is never that simple ... but it might be worth a try.)
But frankly,
cisb.justice.qld.gov.au
is not that "over the top".