I’m writing a Java component that will be doig pretty heavy-duty work on some big data. Obviously, therefore, efficiency (both speed and memory) is paramount.
I’m also just starting to work with IoC and dependency injection frameworks for the first time (such Spring AOP, Google Guice, etc.), and was wondering if they could help me out at all.
What I’d like to do is something like this (all throughout my code):
List<MyData> oMyData = new List<MyData>();
Then, in some XML config file (or however the framework configures injections), I would specify that every time an instance of List is created, to inject, say, an ArrayList<MyData> as its implementation.
This way, if, down the road, I decide to use a different implementation, or even something homegrown that suits my application more efficiently than anything provided by Java Collections, I only need to change the class that gets injected. No other modifications would be necessary, and my code will run that much more efficiently.
Is this is a possible solution, or is this just big dreaming? Again, because I’m so new to IoC frameworks it’s tough to tell what objects injections will work on, whether generics can be preserved during injection, and all sorts of other complicating details I can’t seem to find answers to anywhere else.
Thanks in advance for any insight or recommendations!
This does not sound like a classic scenario for an IOC container, but you could use a factory method.
Use this factory method all over your app. Now if you want to use a different list implementation, just change this method. Look mom, no container needed.
Just to be clear: IOC is an awesome concept. But I don’t think what you are talking about is a classic scenario for IOC.