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?

9
  • @DocBrown: That doesn't appear to be a duplicate, although the OP can probably find his answer there. Commented Oct 8, 2013 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
    Commented Oct 8, 2013 at 21:02
  • @DocBrown: Pretty much has to be exact to be a duplicate. The questions, not the answers. Just sayin'. Commented Oct 8, 2013 at 21:05
  • @RobertHarvey 'No argument about how exact an "exact duplicate" needs to be.' Just quotin' guidelines on duplicates
    – gnat
    Commented Oct 9, 2013 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
    Commented Oct 9, 2013 at 6:53

1 Answer 1

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.

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