Archives

Archives / 2008 / January
  • 对IOC和DI的理解

    首先说一下什么是IOC和DI,IOC是Inversion of Control(控制反转)的简写,DI是Dependency Injection(依赖注入)的简写,martinfowler对IOC的解释为:“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.”
    我想对这一概念进行一个个人的阐述,以方便我的理解。控制反转,从字面意思来看,就是控制权由被动变主动又变为被动,或被动变主动又变为被动。从这个角度来说,IOC就变得非常容易理解了。
    举个例子:你的主管要求你做一件事情,这个时候就存在这么几个过程,