What is and what is AOP IOC

A, the IOC
first: IOC (Inverse of Contro) Inversion of Control, also sometimes referred to as DI dependency injection, which is a one design object thought to reduce the coupling relationship.

 1. Concept introduced:
      1.1 In general, layered architecture used in development, is lower upper caller interface, rely on the underlying upper performed, which makes the callee caller dependent. So now between the caller and the callee wrong was in close contact, if the party is now to be changed, it will cause the program to get a larger change, obviously this is inappropriate, which reduces the program was scalability.

      . For example: now you have to give a sell tea to make a business management system: the business started by selling a green tea, but now extends the business to begin selling tea, the traditional way we will for the abstract base class tea, green tea only need to inherit the base class can be.

With the above-implemented method, when needed GREENTEA only need to perform the following code, AbstracTea tea = new GreenTea (); This mode is to meet the design requirements, but the evident disadvantage is poor scalability if not now find businesses selling green tea, black tea to start selling, then theoretically only need to implement a Black class, and let this class can inherit AbstracTeam class, however, the system uses all AbstracTea tea = new greenTea (); the place needs to be adapted into AbstracTea tea = new BlackTea (); and this creates an instance of the way often lead to changes in the amount of program is very large.

1.2 So the question is, how to do it can enhance system scalability that we can think of it first way is to use the factory pattern to create an object's behavior wrap up?:

Through the above way, we create an object of the process entrusted to TeaFactory done when needed using Tea objects only need to call gettea factory class method to specifically create a logical object class tired we put the factory to achieve, when businesses need to change the tea category, we just need to change the logic to create an object factory class, so that you meet the scalability of the system.

2.IOC
2.1 factory model mentioned above, although the enhanced scalability of the system, but in essence, the factory pattern is only logical move would be to change the factory class which, when the system classes more, expansion of the system makes the systems often need to change the code for the factory class, but we have adopted a design concept IOC, the program will have better scalability:

 

Published 72 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/qq_39399966/article/details/104313531