A look at Dependency Injection and Inversion(devdirective.com)

submitted by RobertTheGreyRobertTheGrey(447) 7 months, 6 days ago

There seems to be a fair amount of confusion around this topic, a particularly useful tool in the SOLID toolbox, but in the wrong hands can go horribly wrong. Let's try and set the record straight now...

6 comments |category: |Views: 574

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

posted by vijaystvijayst(1311) 7 months, 6 days ago 0

The article has very good references to understanding the Dependency Injection and Inversion of Control pattern. I used to talk about these two patterns as if they are the same. It is good to know the subtle difference.

Reply

posted by NoldorinNoldorin(829) 7 months, 5 days ago 0

Good job here. This does presents a pretty good collection of links and summaries. However, I must take point slightly with the definition of "Dependency Inversion Principle" -- the term 'pattern' is used very loosely these days, and I don't think it's correct in this case -- a principle is a principle, and that's it. "Depdendency Injection" here is really the pattern, if anything -- an implementation detail -- it should (if done correctly) be a way to implement the aforementioned *principle* (or 'maxim' as I prefer to call it).

Reply

posted by RobertTheGreyRobertTheGrey(447) replied to NoldorinNoldorin(829), 7 months, 5 days ago 0

That's an interesting point you bring up. The very problem here is that people think they are the same thing. They are different. One does not achieve the other. It's easy to put an interface in the constructor parameter, throw an instance at it and call that "Dependency Injection". That does not mean that you've inverted the dependencies though that that the objects have been properly decoupled. Only by inverting the dependencies can one achieve that, but all to often I see developers pointing at code saying - "See, I'm passing in the dependency, they're loosely coupled now.".

In most of those cases I was able to show the flaw in their thinking, but until they thought of them as separate, they went ahead and made the same mistake again. This article is an effort to show their differences, not the similarities :)

Reply

posted by NoldorinNoldorin(829) replied to RobertTheGreyRobertTheGrey(447), 7 months, 5 days ago 0

Sure, but I still say the latter is a *common way* to carry out the former (principle).

Also, I was just being a stickler with terminology. :-)

Reply

posted by RobertTheGreyRobertTheGrey(447) replied to NoldorinNoldorin(829), 7 months, 5 days ago 0

Agreed - I guess I find that talking about Dependency Inversion in practical terms, the word "principle" feels a bit esoteric to me, kind of like trying to define "good behavior" to a child - lost of room for misunderstanding. I guess the same could be said of "pattern", but it just feels closer to code :)

Reply

posted by NoldorinNoldorin(829) replied to RobertTheGreyRobertTheGrey(447), 7 months, 5 days ago 0

Yeah, that's fair enough. Software developers tend to be practical people, by nature. :-) I guess it's the physicist in me wanting to deal with principles and maxims heh!

Reply

information Login or create an account to comment on this story