Here is the script. As the creator of open source publicly licensed APIs, my group has created a Java-based user interface platform (so what else is new?). So that everything is well and organized as it should in Java, we used packages with the naming convention org.mygroup.myframework.x, with x being things like components, validators, converters, utilities, etc. (again, what else is new?).
Now, somewhere in the class org.mygroup.myframework.foo.Bar there is a void doStuff() method that I need to execute logic specific to my structure and I need to be able to call it from several other places in mine, for example org .mygroup.myframework.far.Boo. Given that Boo is neither a subclass of Bar, nor in the same package, the doStuff () method must be declared public to call Boo.
However, my infrastructure exists as a tool that allows other developers to create simpler and more elegant RIAs for their customers. But if com.yourcompany.yourapplication.YourComponent calls doStuff (), this can have unexpected and undesirable consequences. I would prefer that this never be allowed. Please note that Bar contains other public methods.
In the ivory tower world, we are rewriting the Java language and inserting the tokenized analogue into standard access, which will allow any class in the package structure of our choice to access my method, perhaps similar to:
[org.mygroup.myframework.*] void doStuff() { .... }
where a wildcard will mean that any class whose package starts with org.mygroup.myframework can call, but no one else.
Given that this world does not exist, what other good options do we have?
Note that this is motivated by a realistic scenario; names have been changed to protect the perpetrators. There is a real structure in which, throughout your Javadok, you can find social methods that are commented on as "THIS METHOD IS INTERNAL TO THE MYTHRAME AND NOT A PART OF ITS PUBLIC API. DO NOT CALL !!!!!!" A little research shows that these methods call from other sources within.
In truth, I am a developer using the framework in question. Although our application has been deployed and is successful, my team has experienced so many problems that we want to convince our bosses to never use this structure again. We want to do this in a well-designed presentation of weak design decisions made by the developers of the framework, and not just as a rant. This problem will be one (of several) of our points, but we simply cannot say how we could do it differently. There was already a lively discussion at my workplace, so I wondered what the rest of the world would think.
Update: there are still no offenses for the two defendants, but I think you missed the mark, or I did not express it very well. In any case, I can try to highlight things. Try your best, as the developers of the framework reorganized the following. Please note that this is a really rude example.
package org.mygroup.myframework.foo; public class Bar { /** Adds a Bar component to application UI */ public boolean addComponentHTML() { // Code that adds the HTML for a Bar component to a UI screen // returns true if successful // I need users of my framework to be able to call this method, so // they can actually add a Bar component to their application UI } /** Not really public, do not call */ public void doStuff() { // Code that performs internal logic to my framework // If other users call it, Really Bad Things could happen! // But I need it to be public so org.mygroup.myframework.far.Boo can call } }
Another update: So, I just found out that C # has an “internal” access modifier. Therefore, perhaps the best way to formulate this question could be as follows: "How to simulate / emulate internal access in Java?" However, I am not looking for new answers. Our boss eventually agreed with the problems mentioned above.