How to hide the internal structure of the Java API to the rest of the world
•
Java
I'm developing a Java API to do things (secret, uh, them)
Is there any way to hide classes and the internal structure of APIs?
I have found so far:
>Use internal classes (ugly way, I don't want to put them all in the class file) > all classes are in one package so that I can use "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!
Solution
>Use the interface to define your
About this comment:
One way to implement my second bullet is to use a service to find classes, such as
public class Lookup { private static final Foo foo = new FooImpl(); public static Foo getFoo() { return foo; } }
Foo is an interface and fooimpl is an implementation class (it can be private if you want to force it not to be instantiated by the client)
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码