1

Is it accurate to say that dependency injection manually using java (without spring) is nothing but implementing the strategy pattern (as per this example)?

Furthermore, is it correct to say that Spring just provides a declarative way of specifying the dependency as opposed to manual method whereby the dependency need to be created and 'set' using java code?

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673
Kaushik
  • 1,195
  • 3
  • 12
  • 20
  • @DocBrown: That doesn't appear to be a duplicate, although the OP can probably find his answer there. – Robert Harvey Oct 08 '13 at 20:58
  • 1
    @RobertHarvey: IMHO the other question may not be exactly a duplicate, but it covers the same ground and the answers there will provide also good answers here. – Doc Brown Oct 08 '13 at 21:02
  • @DocBrown: Pretty much has to be exact to be a duplicate. The questions, not the answers. Just sayin'. – Robert Harvey Oct 08 '13 at 21:05
  • @RobertHarvey _'No argument about how exact an "exact duplicate" needs to be.'_ Just [quotin'](http://meta.stackexchange.com/q/166707/165773) guidelines on duplicates – gnat Oct 09 '13 at 03:48
  • 1
    @DocBrown your observation looks accurate, particularly regarding answers - I think that top two and especially [top third](http://programmers.stackexchange.com/a/92438/31260) make a great match to the question asked. Which is not surprising, given the role of DI in Spring – gnat Oct 09 '13 at 06:53
  • @gnat: Well, that's fine, I guess. You guys apparently didn't read the first paragraph of the question, which the duplicate does not address at all. – Robert Harvey Oct 09 '13 at 16:17
  • @DocBrown: The duplicate makes no mention of the strategy pattern. – Robert Harvey Oct 09 '13 at 16:17
  • @RobertHarvey if you delete the second paragraph, I'll be the first to vote reopen (or flag to re-close). [Easy peasy](http://meta.stackexchange.com/questions/194476/someone-flagged-my-question-as-already-answered-but-its-not/194495#194495) – gnat Oct 09 '13 at 21:34
  • @gnat: I think the problem is the title. I've edited it, and voted to reopen. – Robert Harvey Oct 09 '13 at 22:59

1 Answers1

3

Dependency injection (whether done through the constructor or with a DI framework) is one way to implement the strategy pattern, but so is a factory method.

In general, DI frameworks (like the one implemented by Spring) allow you to declare system-wide injection dependencies in a single location.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673