I think the answer is no , but is there a way to make a class private, but in that private class declare an exception which will allow another class to access it's methods? I want to do this for flow control witin the program, so that all the classes in a specific package must go through a 'master' class.
I can't quite tell what that is all supposed to mean, but it all sounds like a bad idea to me. I guess what would help most is if you defined "go through" more clearly. Right now I have no idea what "going through" a class is supposed to do or what benefits you think it would have. Flow control? I don't get that either.
You can have a "master" class with private variables referencing instances of these other classes. Would that accomplish what you're after?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Feb 16, 2008
Thanks for the replies.. let me try to clarify what I mean. I am trying to 'lock down' the code a bit, to help make bugs easier to track down, and to keep a handle on the flow (how data is traversing the program). This is a mid-sized app worked on by myself and 2 other people (one of which speaks very little English). It has been setup where all the controller classes are package visible, but there is a main controller class which is public visible and contains a gateway to all the methods in the package controllers that should be accessible outside of that scope. There are also many package static's in the main controller. The idea behind this design was to prevent other packages from acting as controllers, and catch any that do. It has worked to some extent, but I'd like to take that a step further and lock down each individual class in the controller package as private, but still allow the main controller piece to call the private class' methods. It's an insurance policy I guess...
In a nutshell, I�m trying to make sure our small group of developers follow the design, catch their mistakes, and aid in tracking bugs. Does that make more sense?
Edit: Included an image which might help with clearing up what I'm asking. ControllerA, B, C, and D can only be accessed by the MainController. And, all of these are in the same package. These are static classes (not instantiated objects). These classes are acting upon objects which are stored in the MainController.
Agree with Marc and Paul. What you have written appears to be a contradiction in terms in Java, though maybe not in other languages which have more granularity of access control.
No object can "claim access" of an object of another class; the other class grants access. If you have 4 controllers in the same package with package-private access, then all 4 other classes on your diagram will have access to them. If you really want to restrict access by making the other classes private, they would have to be inner classes of the MainController class, and might still have access to one another.
Joined: Feb 16, 2008
Yeah I thought that was the case but just wanted to make sure. Thanks again for the info.