yeafee@夜飞郎

it's usually better to solve problems with simplicity and finesse rather than muscle.

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  33 随笔 :: 3 文章 :: 2 评论 :: 0 Trackbacks
Understanding inversion of control

        IoC(Inversion of control)是Spring的心脏,听着感觉它比较晦涩。其实它远不像听着的那样难懂。事实上,在你的工程中引入IoC之后,你会发现你的代码会变得非常简朴,更易于理解和测试。
       但是,究竟什么是IoC呢?
Injecting dependencies                        
In an article written in early 2004, Martin Fowler asked what aspect of control is being inverted. He concluded that it is the acquisition of dependent objects that is being inverted. Based on that revelation, he coined a better name for inversion of control: dependency injection.

Traditionally, each object is responsible for obtaining  its own references to the objects it collaborates with (its dependencies). As  you'll see, this can lead to highly coupled and hard-to-test code.Applying IoC, objects are given their dependencies at creation time by some external entity that coordinates each object in the system.That is, dependencies
are injected into objects. So, IoC means an inversion of responsibility with regard
to how an object obtains references to collaborating objects.

 IoC in action                                        

      
posted on 2005-12-13 15:47 @yeafee 阅读(349) 评论(0)  编辑  收藏 所属分类: OpenSource

只有注册用户登录后才能发表评论。


网站导航: