sdk development: restricting access from outside
I need to develop an SDK which will be consumed by the third party writers. I've the following issue:
I have factory methods which can be called to get an instance (say for example a database Connection). These instances are very critical and hence third party code should not be able to get these instances. At the same time my code which is in multiple packages should be able to access.
My packages will be something like:
I mean all these packages start with 'src.sdk' while the thirdparty code will not be in src.sdk.*
I was hoping that package private access would help me. I thought that if a class is in src.sdk and had package private access, then all the packages which start with 'src.sdk' can access the class. But it is not the case. I mean a class say src.sdk.MyClass with package private access is not accessible to another class say src.sdk.pack1.MyAnotherClass.
Is there anyway to control the access to those factory methods to only my code? Controlling access does not necessarily mean compile time restriction. Even if the method can intelligently know that it is being called from a third party code, it can throw an exception.