Re: Problem with hiding the implementation
Royan <romayankin@gmail.com> writes:
I want to hide class A from an end user,
Make it public, but use an uppercase greek Alpha as its name.
This letter looks exactly like an ?A? - so an end user will
never find out that it is an alpha and he will not be able to
call it.
Another idea:
Make the constructor of A private.
Add an inner class AGenerator to A, which implements a factory
method to create an instance of A. So an object of this inner
class is an A factory object.
Now, add a method ?passAGeneratorToZ? to A, which will call
?Z.acceptAGeneratorFromA? with the factory method.
When Z is loaded, its static initializer then will call
A.passAGeneratorToZ(). This method then will call
?Z.acceptAGeneratorFromA(factoryObject)? to pass a factory
object to the class Z.
Now Z has a factory object for A, which it can use in its
constructor to get a new instance of A. But the end user can
not get the factory object in the same way, because it is
hard-wired in A that it will only be passed to
?Z.acceptAGeneratorFromA? - never to an end user method.