Issue HB 108 raises this question, and it seems to be closed with the comment "I don't know a real usecase."
I think I have a real use case.
I'm building an API that is going into an environment of users that are possibly hostile to me (my end users and I have a common customer who wants them to use my product). As a result, I am making my API extremely defensive.
I have one Manager class, and all other classes are available via factory methods in my Manager class. To defend against my users calling the other classes' constructors (and screwing up my data integrity), I am making the constructors for these other classes private.
I know of only one way for the Manager class to call the private constructors of the other classes: Make the other classes inner classes within the Manager class.
I could give the constructors package scope, and put the classes into the same package as the Manager, but it would not take long for my end users to figure out that they can put their code into the same package and start calling the constructors illegally.
You guys are Java experts (Hibernate is truly awesome), so you can see work-arounds to my solution. However, my users are not Java experts, so I am hoping to stave off the corruption of my data as long as possible.
Thanks for taking the time to read my input!
Chris
P.S. If you guys know of another solution to my problem, I'd love to hear it!
|