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/