The reason why IOC is used.

Source: Internet
Author: User

I use spring. Net to implement the IOC function. The reason why I use IOC to manage object creation is that I want to manage the creation of these objects. Why? We must have a clear understanding in our minds about projects and what we must write.Code, As much as possible can be reused in other places. In other places, it often refers to different software projects. Therefore, we have a goal to implement loose coupling, minimize the associations between different modules. In addition to using IOC, we also need to use interfaces to achieve this goal.

Let's give us an example.ProgramFamiliar examples. Taking the data access layer as an example, we have established a software project framework. Our framework is divided into the business logic layer (BLL), database access layer (DAO ), database (db ). Our database access layer includes the open-source project ibatis. NET and nhib.pdf. Now, we want to save the data. We define an idata interface, which has a save (Object mobject) method. Therefore, we can use IOC to create an idata Interface Class Object, we only need to configure this object in the configuration file to use ibatis. net or nhib.pdf. In this way, we only need to introduce this interface in the call, instead of introducing ibatis. net or nhib.pdf, which reduces the number of ibatis in our software project.. Net or nhib.pdf coupling (reducing software project to ibatis.. Net or Nhibernate dependency, and other Dao Data Access layers such as hql may be used in the future .)

In fact, in addition to the above example, we often encounter software applications, just as the applications of a software in different enterprises are also different, they all have their own special characteristics. For example, in a business, when calculating employees' salaries, some companies also have lunch subsidies, transportation subsidies, and special holiday subsidies, therefore, after calculating the salary, we will create different business logic layer class libraries for different companies. In this way, we only need to configure the DLL suitable for the business logic layer of each organization in IOC, instead of re-compiling the entire software project.

 Original Works from the effort to be lazy, reprint please explain the source of the article: http://www.cnblogs.com/kfarvid/

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.