理解IOC容器的概念和DI
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
posted on 2005-12-23 10:04 bluesky 閱讀(744) 評論(0) 編輯 收藏 所屬分類: 工作總結