Original address http://today.java.net/pub/A/today/2004/02/10/IOC.html reverse control
Inversion of Control: It is actually to transfer control from programs to the framework or container dependency. Dependency INJECTION: is to separate the configuration and program personal feeling: is to configure initialization objects, can be loaded with different implementations to achieve control and implementation Lightweight framework for separation purposes currently using IOC concept
Avalon, Spring, PicoContainer seems to have Hive, but this article has not been touched by one of the most classic articles of IOC. I have printed a lot.
Martin Fowler pays tribute
Inversion of Control Containers and The Dependency Injection Pattern
The article says that IOC is not a new concept. In fact, this concept is to rely on the principle of reversal. The following link Dependency Inversion PrinciPle (PDF file) It seems that the truth of all things is correct, but the implementation and application is very different.
Let's talk about the three models of IOC
It is also called Type1 Type2 Type3, but it is not good to remember its true meaning.
Therefore, "Martin service" gave a new name, respectively.
TYPE1 interface Injection Interface Injection
Before IOC, this mode has been applied. In fact, the principle is that you implemented an interface, then the frame will take the initiative to call it.
In fact, the custom servlet runs to compare this mode.
Only
Avalon supports this mode
TYPE2 set value injective setter injection
Initialization using bean's setter
One of the benefits is that JUnit test can be made very well, because as long as you change a configuration file, you can test a variety of configurations (Spring is like this)
The bad place is that Spring requires exposure of the Setter and Getter methods, and there is no way to hide the general attribute.
Martin suggests that the method of using set *** init () is used in this mode, but I feel more troublesome.
TYPTOR INJECTION
This model comes from
"Good citizen." Mode (did not hear, but guessing can ensure that the city is fully equipped, huh, ....)
Really mean to ensure that the object is complete and effective when it is created, eliminating the exposure property issued by Setter Injection
However, this model also has a problem is that the inheritance of the class will lead to some complex design.
Moreover, it is generally said that a class constructor may not only initialize the object, but also contain other purposes, so there is still a selective use.
By the way, talk about DAO mode
Sun's
You can see after Pattern Catalog, now there is no time to see
Like normal beans, define ways to access data, but access is achieved by an abstract data access object (Abstract Data Access Object)
The difference between Spring and PicoContainer
Let me talk about Pico, one mean one means this container is particularly small, meaning it is the smallest, huh, huh, this is in line with the concept of the lightweight container.
A bit metamorphosis ...
Universal
Spring can use XML configuration bindings to access directly through Java
PicoContainer can only be bound through Java (
PicoExtras project provides support for Pico binding XML)
But now N multi-frame and open source projects use XML configuration, which is also a headache, but although it is called Good Taste, but not to Pico relative to Sring is more lightweight, but the support of other projects is relatively weak, such as Hibernate.
And Spring not only provides IOC, providing AOP support
However, the support of AOP can be considered
Aspectwerkz or askectj.
Both supports constructor inject, but only Spring supports setter INJECTION, so choose the only Spring this unique option (translation comparison)