如何在Java中正确组织和嵌套软件包 [英] How to properly organize and nest packages in Java

查看:54
本文介绍了如何在Java中正确组织和嵌套软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照 Java教程进行软件包命名约定我将使用以下方法:

Going by the Java Tutorial for package naming convention if I were to use the following approach:

org.example.hyphenated_name.user

org.example.hyphenated_name.product

这将如何转换为实际创建此程序包结构.我会为org创建一个单独的程序包,然后在org中创建example,依此类推,还是只是两个程序包org.example.hyphenated_name.userorg.example.hyphenated_name.product

How would this translate to actually creating this package structure. Would I create a separate package for org then within org would i create example and so on or would it just be 2 packages org.example.hyphenated_name.user and org.example.hyphenated_name.product

基本上我想知道的是.是仅用于命名分隔还是用于每次物理创建新软件包.

Basically what I'm wondering is if the . is just used for naming separation or if it's used to mean physically creating a new package each time.

推荐答案

包不是必须创建的东西"(除非通常必须创建用于存储源文件的目录层次结构).您几乎只是说您的类属于某个包,而编译器会说好,随便什么". package_a.package_bpackage_a.package_b.package_c之间没有对语言语义有任何影响的内置关系. (我的意思是,如果您在package_a.package_b.package.c中有一个类,那么在该类中与package_z.package_y相反,在package_a.package_b中的类没有什么特别的.在两种情况下,它都是其他一些包".)

A package isn't a "thing" that you have to create (except that you normally have to create the directory hierarchy for storing the source files). You pretty much just say that your class belongs to some package, and the compiler says "OK, whatever you want". There's no built-in relationship between package_a.package_b and package_a.package_b.package_c that has any effect on language semantics. (What I mean here is that if you have a class in package_a.package_b.package.c, then within that class there is nothing special about classes in package_a.package_b as opposed to, say, package_z.package_y. In both cases, it's just "some other package".)

这篇关于如何在Java中正确组织和嵌套软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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