i am developing a SDK in java and my issue is hiding certain java classes/packages so that no third party application using this sdk is exposed to these underlining class's
I know that if all class objects in the sdk were all inside one package i can assign default/protected access modifiers to the class i want to hide. However, like lots of java projects, a java project like my sdk consists of different packages that group the relivant java class's appropriately.
This means that if i want to hide/protect a class thats in com.a.b.c, The main root class thats visible to the world located in com.a wont be able to access classes protected in com.a.b.c etc
How can i provide a solution to this instead of just dumping all classes in one large package?
Thanks.
The Java namespace and access modifiers are not hierarchical, even if that seems to be as of the namespace structure made of folders. Java really has a flat namespace with arbitrary full qualified names (dot notation).
So if you want to close-up your library classes and use it in the library the same time, there is no other way to put them in the same package. Maybe best to explain: when you use a class outside the package this class makes part of the API, as every package in Java is a module.
You could factory classes in the sub-packages and use interfaces. That way you can hide your implementation classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With