美文网首页
Dependency Injection(DI) and Inv

Dependency Injection(DI) and Inv

作者: 沥人土土 | 来源:发表于2017-04-11 09:16 被阅读0次

Dependency Injection(DI):

DI flavor of Inversion of Control. The Inversion of Control(IoC) is a general concept, and it can be expressed in many different ways and Dependency Injection is merely one concrete example of Inversion of Control.
Dependency Injection helps in gluing these classes together and same time keeping them independent.
Dependency injection can happen in the way of passing parameters to the constructor or by post-construction using setter methods.

Inversion of Control(IoC)

优缺点
优点:
把对象生成放在了XML里定义,使换一个实现子类变得很简单(用于实现某种接口的对象), 只要修改XML就可以,甚至可以实现对象的热插拔。
缺点:
1)生成对象步骤变复杂
2)使用反射编程,效率损耗。(损耗<提高的灵活性和维护性)
3)缺少IDE重构操作支持

实现方式:
实现数据访问层
模块与接口重构
随时增加单元测试
使用服务定位器而不是构造注入

Spring Architecture


Image.png

相关文章

网友评论

      本文标题:Dependency Injection(DI) and Inv

      本文链接:https://www.haomeiwen.com/subject/polyattx.html