Benefits of Dependency Injection

Source: Internet
Author: User

Benefits

    • The creation code of the dependent class is removed from the dependency class without explicitly writing new.
    • The creation of dependent classes can be maintained separately.
    • Facilitates the sharing of this class.

      If the class is initialized with a lot of properties, using configuration is much simpler than hard code writing.

      For example, when DataSource configures a database connection pool.
    • When there are multiple layers of dependencies, the removal of dependencies actually simplifies the view and maintenance of dependencies.
    • Because for each class, you only need to be concerned about the dependency of this class.

      In the case of Web projects, the controller layer only needs to care about the service layer, and the service layer only needs to care about the DAO layer.

      It is possible to implement logic in a method by using more than n DAO in a service.

      But the controller simply refers to this service and calls this method.

Benefits of Dependency Injection

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.