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?

  • @DocBrown: That doesn't appear to be a duplicate, although the OP can probably find his answer there. – Robert Harvey Oct 8 '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 8 '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 8 '13 at 21:05
  • @RobertHarvey 'No argument about how exact an "exact duplicate" needs to be.' Just quotin' guidelines on duplicates – gnat Oct 9 '13 at 3:48
  • 1
    @DocBrown your observation looks accurate, particularly regarding answers - I think that top two and especially top third make a great match to the question asked. Which is not surprising, given the role of DI in Spring – gnat Oct 9 '13 at 6:53

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.