Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide the internal structure of a Java API to the rest of the world

i am developing a Java Api to do things (secret, uhhhh ;).

Is there a way to hide classes, and the internal structure of my API?

What i found until now:

  • Using inner classes (ugly way, i do not want to put all in on class file)
  • All classes in one package so that i can use the "package"-visibilty (also ugly, i need more packages)

Example:

---
package net.my.app;
//this is the Public Access
class MyPublicClass{
    public void somePublicFunction(){ 
        //access to not visibil classes
    }
}

---
package net.my.app.notvisible:
//this is what i want to hide
class MyNOTPublicClass{
    ...
}
---

Any ideas? Thank you!

like image 363
CoffeJunky Avatar asked May 03 '11 15:05

CoffeJunky


1 Answers

There are two solutions to your question that don't involve keeping all classes in the same package.

The first is to use the Friend Accessor/Friend Package pattern described in (Practical API Design, Tulach 2008).

The second is to use OSGi.

Related Questions: 1, 2, 3, and 4.

like image 100
Jeff Axelrod Avatar answered Sep 21 '22 05:09

Jeff Axelrod