【问题标题】:java packages - how to handle repeating namesjava包 - 如何处理重复的名字
【发布时间】:2017-06-22 20:30:31
【问题描述】:

按如下方式组织“导出”是否有意义?不确定这是否足够普遍或完全推荐的做法。

org.mycompany.export.generic-export-utilities
org.mycompany.productA.export.productA-specific-export-logic
org.mycompany.productB.export.productB-specific-export-logic

【问题讨论】:

  • “有组织”是指按字母顺序排列的吗?还是别的什么?
  • 我的意思是同名“export”在命名空间中出现在较高位置,然后在较低位置。从技术上讲这没问题,但从设计的角度来看并不直观。

标签: java package


【解决方案1】:

我认为这是一个很好的问题。

嗯,组织包的一个好方法是用“域”分隔代码。如果没有应用程序的上下文,很难推荐一个好的包组织。但我会尽力帮助你。

请参阅此示例。您有一个管理学生和客户的系统。一种很好的组织方式:

org.mycompany.student
org.mycompany.student.dto
org.mycompany.student.service
org.mycompany.customer.dto
org.mycompany.customer.service

不好的方法#1:

org.mycompany.dto.student
org.mycompany.dto.customer
org.mycompany.service.student
org.mycompany.service.customer

不好的方法#2:

org.mycompany.student.dto-student
org.mycompany.student.service-student
org.mycompany.customer.dto-customer
org.mycompany.customer.service-customer

在这两种情况下,我们有一些包名重复。

所以,回到你的问题,也许这对你来说更有意义:

org.mycompany.export.utils //I'm outside of the products subpackages, so this means that this is the place for generics utilities
org.mycompany.productA.export //i'm already in the export inside the productA, this organization already show that the classes inside are specific for productA
org.mycompany.productB.export //i'm already in the export inside the productB, this organization already show that the classes inside are specific for productB

【讨论】:

    猜你喜欢
    • 2018-12-05
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-29
    • 1970-01-01
    • 2020-05-02
    相关资源
    最近更新 更多