I have a package ts
, containing interfaces for ticket system. I also have hts
package, containing concrete implementation of ts
. I have TicketSystem.class
in ts
, and HTicketSystem.class
in hts
extended from it the first one. HTicketSystem.class
is the only public class in hts
package. All other classes in hts
have default visibility. hts
package has lots of files, among them java beans. I'd like to extract these beans to sub-package hts.beans
. The obvious problem then is visibility, because according to JLS
:
7.1 Package Members
...
The hierarchical naming structure for packages is intended to be convenient for organizing related packages in a conventional manner, but has no significance in itself other than the prohibition against a package having a subpackage with the same simple name as a top level type (§7.6) declared in that package. There is no special access relationship between a package named oliver and another package named oliver.twist, or between packages named evelyn.wood and evelyn.waugh.
1) If I leave beanA.class
with default visibility, it will not be visible to hts
classes.
2) If I change beanA.class
to public visibility, it will be visible from outside.
Any suggestion/best practice is highly appreciated.