Java subpacking without creating subpackage classes

Say I have 20 classes in my root package. I decided to organize classes by creating 3 subpackages under the root package. Then I put 5 classes in each of the subpackages, leaving 5 classes in the root package (because they are top-level classes). Now, since I need to use classes in subpackages of 5 classes in the root package, I end up making classes in subpackages publicly available, and before the subpackage of these classes will only be exposed to the packages.

The above code organization is done with good recommendations. The subpackage is implemented by function instead of layer. Interdependence in front of packages is minimized. Nevertheless, many classes of subpackages make sense to access from a higher level.

Is there any good practice to solve this type of scenario?

+4
source share
1 answer

Unfortunately no. The most that you have is visibility at the package level, making it closed to the package (default access). You cannot use it to make the class visible only to other classes in the same module. I think the Jigsaw Project and JSR 294 will consider this (in addition to other stuff), but you probably won't see it until Java 9.

+2
source

Source: https://habr.com/ru/post/1535771/


All Articles