The worst way to explain dependency injection
July 28, 2011 2 Comments
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.


Recent Comments