2

您是否遵循 java 包装中的任何设计准则?

适当的包装是设计技巧的一部分吗?有没有关于它的文件?

编辑:包必须如何相互依赖?循环包是不可避免的吗?与 jar 或 war 文件无关。

4

4 回答 4

2

我尝试遵循的方法通常如下所示:

  1. 有合理大小的包裹。少于 3 节课很奇怪。小于 10 是好的。超过 30 是不可接受的。我通常对此不是很严格。
  2. 包之间没有依赖循环。这很困难,因为许多开发人员很难找出任何方法来保持依赖循环自由。但是这样做会梳理出代码中的许多隐藏结构。考虑代码的结构变得更容易,也更容易改进它。
  3. 定义层和模块以及它们在代码中的表示方式。通常我最终会得到类似<domain>.<application>.<module>.<layer>.<arbitrary substructure as needed>包名称的模板
  4. 层与层之间没有循环;模块之间没有循环。

为了避免循环,必须进行检查。许多工具都可以做到这一点(JDepend、Sonar ...)。不幸的是,他们在寻找修复周期的方法方面没有多大帮助。这就是我开始研究Degraph的原因,它应该通过可视化类、包、模块和层之间的依赖关系来帮助解决这个问题。

于 2013-02-02T17:41:41.943 回答
1

Packaging is normally about release management, and the general guidelines are:

  • consistency: when you are releasing into integration, pre-production or production environment several deliveries, you want them organized (or "packaged") exactly the same way

  • small number of files: when you have to copy a set of files from one environment to another, you want to copy as many as possible, if their number is reasonable (10-20 max per component to deliver), you can just copy them (even if those files are important in size)

So you want to define a common structure for each delivery like:

aDelivery/
    lib // all jar, ear, war, ...
    bin // all scripts used to launch your application: sh, bat, ant files, ...
    config // all properties files, config files
    src // all sources zipped into jars
    docs // javadoc zipped 
    ...

Plus, all those common directory structures should be stored into one common repository (a VCS, or a maven repo, or...), in order to be queried, without having to rebuilt them every time you need them (you do not need that if you have only one or two delivery components, but when you have 40 to 60 of them... a full rebuilt is out of the question).

于 2009-03-24T05:01:43.573 回答
0

你可以在这里找到很多信息:

您在 Java 项目中使用什么策略来命名包,为什么?

于 2009-03-24T08:18:35.317 回答
0

Java 中打包的问题在于它与您想做的事情几乎没有关系。例如,我喜欢遵循将包标记为内部的 Eclipse 约定,但是我不能用“包”保护级别定义它们的类。

于 2009-05-11T03:35:57.850 回答