How to eliminate a parameter boom

Hello folks. Today I want to write about a little trick I learned. If you are working with legacy code and you don’t have the chance to eliminate core design problems, you can use this little pattern to help you out. Problem Problem is that you have a class that has a gazillion collaborators and at some point in time one of the clever devs thought it would be a cool idea to do dependancy injection via the constructor. We all know that doing this makes the class immutable which is very good for a number of reasons. However it doesn’t provide a flexible solution if you want to leave out one or two collabs. For that your would have to create Adapter constructors and chain them upwards which would get very ugly very fast. While using JavaBeans getters and setters can leave your class in a harmful state like not at all or partially initialised. ...

October 9, 2012 · 3 min · hannibal