Inversion of Control/Dependency Injection
IOC容器相当于一个bean工厂,来管理整个应用程序中使用的bean,来管理这些bean的生命周期;
实现IOC/DI是通过一堆描述文件,IOC容器根据这堆描述文件来实现创建对象提供服务等工作;
一般情况下,我们通过new一个对象并调用这个对象的某个方法来完成服务.
既然有了IOC容器管理概念,那么通过描述文件容器就为我们创建所需要对象和方法.
好处就是减少了硬编码.
There are three different implementation pattern types for IoC:
type-1 |
Services need to implement a dedicated interface through which they are provided with an object from which they can look up dependencies (other services). This is the pattern used by the earlier containers provided by Excalibur. |
type-2 |
Services dependencies upon are assigned via JavaBeans properties (setter methods). Both HiveMind and Spring use this approach. |
type-3 |
Services dependencies are provided as constructor parameters (and are not exposed as JavaBeans properties). This is the exclusive approach used by PicoContainer, and is also used in HiveMind and Spring. |
http://jakarta.apache.org/hivemind/ioc.html
http://www.javaworld.com.tw/confluence/display/opensrc/Spring