Spring's IOC Learning

Source: Internet
Author: User

I've seen an example of IOC before, but I've never been able to make it clear, just know that the work of creating the object is given to the framework, not new, but what is the principle? Why do you want to do this or not? It can be seen that the underlying principle of the IOC is the knowledge of reflection.

Reflection is a dynamically generated object based on the given full class name (string), which allows the object to be determined at the time of generation, so it can be assumed that, in a configuration file, the file is already well-written with the fully qualified name of the Bookdaoimpl class. The real implementation class fully qualified name of the Bookdao is obtained by reading the file, and then the object of the class is dynamically generated at run time by the reflection technique, which is eventually assigned to the Bookdao interface

Large decoupling can be achieved by modifying the configuration file rather than by modifying the code.

Then using reflection to create the actual implementation class for Bookdao at run time, including the creation of the Bookserviceimpl, the spring IOC container will do the work for us, The only thing we have to do is to tell the IOC container what classes to create and what classes to inject in the configuration file as the classes and other class-dependent classes that need to be created.

Spring's IOC Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.