What does IOC stand for? IOC的概念,DI
2011-10-31 00:55
323 查看
http://martinfowler.com/articles/injection.html
The question, is what aspect of control are they inverting? When I first ran into inversion of control, it was in the main control of a user interface. Early user interfaces were controlled by the application program. You would have a sequence of commands like "Enter name", "enter address"; your program would drive the prompts and pick up a response to each one. With graphical (or even screen based) UIs the UI framework would contain this main loop and your program instead provided event handlers for the various fields on the screen. The main control of the program was inverted, moved away from you to the framework.
Figure 2: The dependencies for a Dependency Injector
There are three main styles of dependency injection. The names I'm using for them are Constructor Injection, Setter Injection, and Interface Injection. If you read about this stuff in the current discussions about Inversion of Control you'll hear these referred to as type 1 IoC (interface injection), type 2 IoC (setter injection) and type 3 IoC (constructor injection). I find numeric names rather hard to remember, which is why I've used the names I have here.
Inversion of Control
When these containers talk about how they are so useful because they implement "Inversion of Control" I end up very puzzled. Inversion of control is a common characteristic of frameworks, so saying that these lightweight containers are special because they use inversion of control is like saying my car is special because it has wheels.The question, is what aspect of control are they inverting? When I first ran into inversion of control, it was in the main control of a user interface. Early user interfaces were controlled by the application program. You would have a sequence of commands like "Enter name", "enter address"; your program would drive the prompts and pick up a response to each one. With graphical (or even screen based) UIs the UI framework would contain this main loop and your program instead provided event handlers for the various fields on the screen. The main control of the program was inverted, moved away from you to the framework.
Forms of Dependency Injection
The basic idea of the Dependency Injection is to have a separate object, an assembler, that populates a field in the lister class with an appropriate implementation for the finder interface, resulting in a dependency diagram along the lines of Figure 2Figure 2: The dependencies for a Dependency Injector
There are three main styles of dependency injection. The names I'm using for them are Constructor Injection, Setter Injection, and Interface Injection. If you read about this stuff in the current discussions about Inversion of Control you'll hear these referred to as type 1 IoC (interface injection), type 2 IoC (setter injection) and type 3 IoC (constructor injection). I find numeric names rather hard to remember, which is why I've used the names I have here.
相关文章推荐
- What does PEP stand for in Python
- What does grep stand for in Linux operating system?
- What does RC stand for?
- IoC与DI概念
- SpringBoot基本概念及快速入门(IOC/DI)
- What does Class.forName(); do?
- 一、IOC和DI的概念
- what does Html.HiddenFor () for ?
- IoC容器Autofac之IOC/DI基本概念(二)
- What does it mean for an algorithm to be fair
- IoC与DI概念
- 关于spring的两个概念:IoC(控制反转) ,DI(依赖注入)
- 谈谈Spring中的IOC、DI和AOP概念
- 053-19 What recommendations does the SQL Access Advisor provide for optimizing SQL queries? (Choose
- IOC/DI与AOP概念的理解(转载及修改)
- IOC/DI与AOP概念的理解
- DIP、Ioc、DI、Ioc容器概念
- What does Class.forname method do?
- Spring ioc Di概念
- Spring.Net---2、IoC/DI基本概念