Spring in Action 学习笔记 2(Understanding inversion of control)

Spring in Action 学习笔记 2(Understanding inversion of control)
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                                        

      

你可能感兴趣的:(Spring in Action 学习笔记 2(Understanding inversion of control))