2010-11-12 94 views
1

可能重复:
What is dependency injection?依赖注入设计模式

Spring使用依赖注入模式。有人可以展示这种模式的一个简单例子吗? 我听说有另一种叫做服务定位器的模式,哪一个更好?

+0

重复:http://stackoverflow.com/questions/130794/what-is-dependency-injection http://stackoverflow.com/questions/1980182/what-are-dependency-injection-spring-framework-about http ://stackoverflow.com/questions/139299/difference-between-dependency-injection-di-inversion-of-control-ioc http://stackoverflow.com/questions/1557781/whats-the-difference-between-the- dependency-injection-and-service-locator-patter – 2010-11-12 02:06:49

+1

请给我一些你一直在问的问题做一些研究。如果你只是看,几乎所有你有疑问的话题都已经被回答了1000次。询问SO是懒惰的出路。 – 2010-11-12 02:53:44

+0

服务定位器是旧学校,依赖注入是新学校:-) – 2010-11-13 08:32:47

回答

1

Service locator是一个J2EE“Core Patterns”的成语。

让我们在讨论它之前定义“更好”,我们可以吗?

他们不是真正的竞争对手,海事组织。并非每个依赖都发生在网络上。 Spring可以做远程处理和代理,但这不是所有依赖关系的总和。