Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Providing Java library, but hiding some classes

Tags:

java

java-me

I am developing an application in Java ME that I want to provide as a library. Is there no way to hide classes that I don't want everyone to use, but is essential still in order for the library to work?

UPDATE: I get that I can omit the public specifier, but how can I structure the library itself while developing without creating different packages? I like to view different packages as different folders simply which allows me to structure the code in a good way. However, in some cases I might need to access classes in other packages so this is rather tricky. What does packages really represents? One idea might be to create "interfaces", but these has to be declared public so that means that foreigners might also implement the interfaces intended only for some processes inside the library, correct?

like image 874
Thomas Johansson Avatar asked Jul 10 '11 18:07

Thomas Johansson


1 Answers

If Java 9 is possible, use Jigsaw modules. If not, put every class on the same package, with package-level access for hidden classes, and use Maven modules to organize them.

I've done exactly that in my project called coronata, a Wii Remote java library. Almost all classes are in package com.github.awvalenti.bauhinia.coronata, but on different modules (which appear as projects on the IDE).

Visible classes are public. They are in modules:

  • coronata-api
  • coronata-builder
  • coronata-demos
  • coronata-lib

Hidden classes have package-level acesss. They are in modules:

  • coronata-common
  • coronata-implementation-bluecove
  • coronata-implementation-wiiusej
like image 57
André Willik Valenti Avatar answered Sep 18 '22 18:09

André Willik Valenti