2

Possible Duplicate:
What is dependency injection?

Spring uses dependency injection pattern. Can someone show a simple example of this pattern? I heard there is another pattern called service locator, which one is better?

Community
  • 1
  • 1
user496949
  • 75,601
  • 138
  • 297
  • 413
  • duplicate: 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 – Mauricio Scheffer Nov 12 '10 at 02:06
  • 1
    Please, please, please do some research yourself on some of the questions you've been asking. Almost all of the topics you have questions on have been answered 1000 times if you would just look. Asking on SO is the lazy way out. – Chris Conway Nov 12 '10 at 02:53
  • Service Locator is old school, Dependency Injection is New School :-) – Sean Patrick Floyd Nov 13 '10 at 08:32

1 Answers1

1

Service locator is a J2EE "Core Patterns" idiom.

Let's define "better" before we debate it, shall we?

They aren't really competitors, IMO. Not every dependency happens over a network. Spring can do remoting and proxying, but that's not the sum of all dependencies.

duffymo
  • 293,097
  • 41
  • 348
  • 541