Enthusiastic Thumbs up for Spring Framework
April 25th, 2004The IOC, Dependency Injection wave is coming into shore for Java developers. The whole IOC idea certainly isn’t new, its just good design.
- Prefer Delegation to Inheritance
- Program to Interfaces
- Decoupling
It seems that something as “simple” as a framework to support these principals would have been happened a long time ago. It’s not that you can’t have good design without a framework, but a good framework should help facilitate good design, and consistency across a system.
One quick disclaimer, I’m endorsing Spring because I have used it and I have gotten results that I’m very pleased with. I’m a little concerned that PicoContainer is falling into the background. From what little I’ve seen PicoContainer seem to be the technically superior IOC container implementation. Unfortunately superior IOC doesn’t seem to be the driving force. The real killer-app of the IOC arena is J2EE simplification, and that’s Spring.
It’s hard to integrate an architecture technology like Spring into a real project with it’s own established architecture. I aimed for the target of the greatest opportunity, our DAO layer. Our application uses generated DAO’s laden with customizations, which present a number of problems.
- Customizations make them very hard to regenerate or tweak
- Profuse boilerplate code makes them very verbose and hard to read.
- Crosscutting concerns like error handling are hard to change
- The verbose boilerplate code encourages cut and paste(and associated errors)
Enter Spring, with its IOC. All the boilerplate code is isolated to one place, with callbacks for the code that really does vary. No more worrying about resources not being handled correctly because a novice was in cutting and pasting. We can still use code generation for the easy PreparedStatementCreator’s, and ResultReader’s, and we can add our own custom PreparedStatementCreator’s and not have to worry about the generator accidentally clobbering them. Transactions are now declarative and we didn’t need to worry about managing them in the application code or using Session EJB’s.
Our DAO layer just got about 10 times more manageable, and it was easy. I will be looking for more opportunities to let Spring make my life easier, and I would encourage any one else to do the same.