Results 1 to 2 of 2
  1. #1
    madhusudhan y is offline Member
    Join Date
    Mar 2011
    Posts
    1
    Rep Power
    0

    Default sdk development: restricting access from outside

    Hi,
    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:
    src.sdk.pack1
    src.sdk.pack2.innerPack1
    src.sdk.pack2.innerPack2
    src.sdk.pack3
    etc.
    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.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default

    Stick the stuff they aren't supposed to use under an obvious package structure.
    Write documentation that explains the bits they are supposed to work with, and points out the stuff under (say) "internal" is not for external use.

    Then if the twits insist on using those classes then it's their own fault.

    Oh and mark them as @Deprecated if you feel really particular about it, but that might confuse your own development.

Similar Threads

  1. Replies: 0
    Last Post: 01-10-2011, 06:26 AM
  2. Replies: 5
    Last Post: 04-23-2010, 06:08 PM
  3. Default Access (package access) confusion
    By gauravrajbehl in forum New To Java
    Replies: 1
    Last Post: 11-18-2009, 10:48 AM
  4. Method access or field access
    By carderne in forum New To Java
    Replies: 2
    Last Post: 12-06-2008, 06:20 PM
  5. Replies: 1
    Last Post: 08-07-2007, 07:51 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •