The worst way to explain dependency injection

I don’t know, but sometimes I feel like I’m talked to like a child. When I read a book about some technology I expect to learn how to use technology too. I remember reading one book about UML with such a nonsense example from real life that it debased the whole explanation and made it ridiculous. Add a few cases where picture said something and description something else and a few flaws that were clear even to new learner (yet still confusing) and you have one of those books I can’t recommend at all (I think it was some older edition of Teach Yourself UML in 24 Hours – and in Czech translation that probably added just more to it).

Now I’m reading (among too many other things) Spring in Action – and there is that first chapter with Knight and Quest and how you can send Knight for a Quest using dependency injection. But who would do that? Now I was thinking: “Is it possible to manage runtime relations with Spring? Can I control entity creation and inject something to them?” What a stupid questions these are when you know what Spring really is, right? But why they are using Knight and Quest? Who would ever create a system with a knight (or a few of them) and *configure* them and their quests with Spring? Obviously – nobody.

And just this evening I was checking presentations from one local Oracle conference and professional Java Developer Advocate was explaining CDI and ManagedBeans with one SpaceCapsule and a Cosmonaut who’s ManagedBean was named “yuri”. How real is such an example? It’s not! It’s misleading altogether and that’s what is likely shown to CDI/DI/IoC newbie nowadays! I just can’t understand why…

Of course, we all play some little games with our code here and there, but I’d expect from new technology introduction also the right way how to use it. What type of situations, when yes and not. I don’t want them to suggest (or just accidentally imply) that I can manage various cosmonauts in my system in CDI – because that’s just wrong. I can name roles for managed beans, what they should act like in this and that scope… but “yuri”? Come on. Stop it. Please.

Or do you, readers, think this is the good way? Maybe it is, I don’t know. Sometimes I’m just off the crowd, really – and not always the right time. 🙂 If you feel it some other way, drop me a line in comments.


About virgo47
Java Developer by profession in the first place. Gamer and amateur musician. And father too. Naive believer in brighter future. Step by step.

2 Responses to The worst way to explain dependency injection

  1. Esben Jensen says:

    Seems you got hold of a children’s book about dependency injection. 😉

    When learning new topics, decoding those friendly, happy terms sometimes turns into a nightmare. Topics related to Java are especially prone to this. Those terms are of course used because they represent completely abstract concepts or contrieved examples in a learning context. But it would help a lot if authors and developers at least tried to use terms that are slightly descriptive or related to real world applications.

    Sometimes I long for programming examples using A, B, C or Foo, Bar, Baz as generic variables instead of Flowers, Bees and Unicorns.


  2. Fero says:

    I think the authors of such books are off the crowd!

    Much better approach is to introduce some not too complicated domain and them speak about it. Great done in e.g. SOA: Concepts, Technology, and Design.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s