Coming from a C++ background I have to master the complexity of the Java world and its frameworks. Looking at the spring framework for DI I am finding it difficult to believe that I have to make each setter function which will be subject for DI public. Doesn’t that requirement break the principle of information hiding?
Of course I want spring to be able to set some private parts of my classes, but I certainly do NOT want every client class to be able to do the same.
What am I missing here?
If you code to interfaces, you only need to expose setters on the implementations. As you inject the interfaces into other parts of the system, they cannot access the implementation details or state of the objects.