Dependency Injection
We have seen earlier in this chapter that we were sending a Datasource object into the constructor method of our UserDAO
object, to provide the connection details for the datasource.
This is an object-oriented programming technique used to provide information to a specific object for it to work with.
Essentially, Dependency Injection (DI) controls what information an object has access to, and therefore, what information it has to work with. Traditionally in procedural programming, an object may have access to information from a variety of sources, and the object itself may have the ability to access and digest this information as needed.
Using Dependency Injection in your object-oriented programming is a highly effective way to control this information; the technique is also known as Inversion of Control (IoC).
This means that the control over what your object receives is inverted and instead of grabbing whatever it needs, the object is provided or fed only the information...