上一篇我们介绍了IoC是什么以及IoC的发展历程,本篇我们一起来看一下IoC的主要实现策略当然我们还是以wiki以及Spring的主要作者的论述为依据,我来为大家讲解一下关于ioc用到的设计模式:IoC的主要实现策略?跟着小编一起来看一看吧!
ioc用到的设计模式:IoC的主要实现策略
上一篇我们介绍了IoC是什么以及IoC的发展历程,本篇我们一起来看一下IoC的主要实现策略。当然我们还是以wiki以及Spring的主要作者的论述为依据。
wiki首先我们来看一下wiki中对于IoC的主要实现策略的介绍:
In object-oriented programming, there are several basic techniques to implement inversion of control. These are:
* Using a service locator pattern
* Using dependency injection, for example
* Constructor injection
* Parameter injection
* Setter injection
* Interface injection
* Using a contextualized lookup
* Using the template method design pattern
* Using the strategy design pattern
In an original article by Martin Fowler,[9] the first three different techniques are discussed. In a description about inversion of control types,[10] the last one is mentioned. Often the contextualized lookup will be accomplished using a service locator
翻译成中文大概的意思就是:在面相对象编程中,这里有以下几种主要实现手段。
* 使用服务定位方式
* 使用依赖注入方式:
* 通过构造器函数
* 通过参数注入
* 通过Setter方法注入
* 通过注入接口
* 通过上下文方式的查找
* 通过模版方法模式
* 通过策略模式
这本书是Spring的两位作者写的,里面提到了IoC的主要实现策略:
IoC is a broad concept that can be implemented in diffrent ways.There are two main types:
* Dependency Lookup
* Dependency Injection
翻译成中文大概的意思就是:IoC是能被不同方式实现的一个非常宽泛的概念。通常来说有两种主要的实现方式:
* 依赖查找
* 依赖注入
从wiki和《Expert One-on-One J2EE Development without EJB》这本书中对于IoC的论述我们可以得出一个结论那就是:实现IoC的主要实现方式主要有两种:
* 依赖查找
* 依赖注入
那么后续我们对于Spring Framework 的IoC实现也将主要从这两方面来讨论。
,