IoC control reversal
Public class personservicebean{ privatenew Persondao (); Public void Save (person person) { persondao.save (person); }}
As shown in the code above, Persondaobean is created and maintained within the application. The so-called inversion of Control (IoC) is that the application itself is not responsible for the creation and maintenance of dependent objects, the creation and maintenance of dependent objects is the responsibility of the external container, so that control is transferred from the application to the external container, the transfer of control is called inversion. Control can understand the management (creation and destruction) of the beans needed to run the application, and if you look at the code as an application, the bean that the application needs to run is Persondaobean.
DI Dependency Injection
When we give the dependent object to the external container for creation, the Personservicebean class can be changed to the following:
Public class personservicebean{ private Persondao Persondao; // by using constructor parameters, let the container put the created dependent object // injected into the Personservicebean can also be injected using setter. public personservicebean (Persondao persondao) { this. Persondao = Persondao; } Public void Save (person person) { persondao.save (person); }}
Dependency Injection: At run time, dependent objects are dynamically injected into the component by an external container.
IOC and Di