You keep saying "hand rolled framework" while the thing being discussed is a basic factory, I have to wonder if you know what a "framework" is as well. The scenario you describe simply doesn't exist. I "hand roll" my wiring precisely because my projects are big and modular, and I need the control inverted to the application boostrap and not scattered around in vague XML files and annotations.
I write this code because I realize it's the most important aspect of my application - the logic that hooks the parts into a whole exactly as I need and not by random happenstance and type name matching.
When you have a project that largely consists of reusable modules, it's not a smart idea to embed project-specific configuration in annotations on supposedly project-neutral components, don't you think?
When you use annotations and autowiring in Spring, do you realize the very point you seem to stress about, namely inversion of control, gets the knife? Annotations represent inversion... of inversion of control. Information that should be specified outside the object is instead embedded back on it, same as would be the case if you directly instantiated dependencies inside it, or fetched from a global service locator.
Spring doesn't assist IoC, in fact it provides tools which quickly and swiftly destroy it.
Ever needed empty "tag" classes and interfaces? Or qualifier annotations? Tell me, how does this fit into the whole "the object is not aware of its environment" concept of IoC. With qualifiers, it seems that the object is painfully aware not just of the existence of a container, but also how is that container configured exactly with qualifiers. This is no IoC.
Inversion of Control doesn't mean 'Information that should be specified outside the object is instead embedded back on it' - but that the concern of creating an object is delegated to an outside party. A factory is a type of IoC - a simple one. I m saying that this simple factory is sufficient, if your needs are simple. Most projects which decide to use spring (or guice, or any number of others) are not simple. The most common case is unit testing, but i m sure there's others.
Regarding the type annotations you claim is the inverse of IoC, the annotation tend to either be a one off (such as @autowire, or @inject) on the constructor. You usually won't have to annotate each param directly, especially with any recent versions of any of the IoC frameworks. There is no information about the dependency embedded in the dependent, other than an interface - which is the whole point.
What you point out regarding qualifiers (and other 'cruft') is a way for old, poorly designed projects/architectures to piecemeal convert over to spring, without big bang rewrites. You are essentially equating features that aren't so good to use (but made necessary because there's legacy code out there) with the whole framework. I dont know how much of it you really have used - perhaps there's been a poor code-base you've used, and it was spring, and it used all the features poorly, and it clouts your judgement.
Inversion of Control doesn't mean 'Information that should be specified outside the object is instead embedded back on it' - but that the concern of creating an object is delegated to an outside party.
Yes, you're putting my quote outside of context. The quote describes how annotations go against IoC. It's not a description of IoC.
I dont know how much of it you really have used - perhaps there's been a poor code-base you've used, and it was spring, and it used all the features poorly, and it clouts your judgement.
Yeah, sure. Please indulge me, let's see how you'd solve the following example scenario:
You have three SQL connections, all of the same class (JDBC connection), but every one of them points to a different database: cache, domain, and archive.
You have several dozen classes that require one or more of the three connections, but to know which one they need, you need to read the object's JavaDoc description of what they use the connection for. They're all of the same type, because... it's just an SQL connection.
So, it's a very basic and common scenario which is absolutely trivial with a factory without violating IoC. How is Spring helping you improve on a basic factory? How, and most importantly, where would you specify which connection goes in which connection parameter?
3
u/[deleted] Nov 30 '15 edited Nov 30 '15
You keep saying "hand rolled framework" while the thing being discussed is a basic factory, I have to wonder if you know what a "framework" is as well. The scenario you describe simply doesn't exist. I "hand roll" my wiring precisely because my projects are big and modular, and I need the control inverted to the application boostrap and not scattered around in vague XML files and annotations.
I write this code because I realize it's the most important aspect of my application - the logic that hooks the parts into a whole exactly as I need and not by random happenstance and type name matching.
When you have a project that largely consists of reusable modules, it's not a smart idea to embed project-specific configuration in annotations on supposedly project-neutral components, don't you think?
When you use annotations and autowiring in Spring, do you realize the very point you seem to stress about, namely inversion of control, gets the knife? Annotations represent inversion... of inversion of control. Information that should be specified outside the object is instead embedded back on it, same as would be the case if you directly instantiated dependencies inside it, or fetched from a global service locator.
Spring doesn't assist IoC, in fact it provides tools which quickly and swiftly destroy it.
Ever needed empty "tag" classes and interfaces? Or qualifier annotations? Tell me, how does this fit into the whole "the object is not aware of its environment" concept of IoC. With qualifiers, it seems that the object is painfully aware not just of the existence of a container, but also how is that container configured exactly with qualifiers. This is no IoC.