← Back to context

Comment by MBCook

3 days ago

Passing a couple objects seems easy. But I’ve seen where it leads in a large program.

Passing things down layer after layer gets old. High level stuff takes tons of parameters due to all the layers below.

You end up with God objects that mostly just contain every other object someone might want to reference.

And you know what? That object starts to feel like a great place to put state. Cause it’s already being passed everywhere.

So instead of using Spring to get a ThingService to work with your Thing at the spot you need it, suddenly all the code has access to all the stuff and states. And like the temptation of The One Ring programmers use it.

Now you have a spaghetti rats nest. Where is the code that deals with the state for a Gloop? It’s now everywhere. Intertwined with the code for a Thing. And a Zoob. It doesn’t need to be. But it is.

It becomes almost impossible to unit test things. Because everything can do/see everything. Untangling and extracting or replacing any part of the whole is a Herculean job.

You don’t need Spring for something tiny. And maybe it’s possible to go without dependency injection in a large app and keep things manageable and easy to understand.

In my career I’ve mostly seen the mess. I’ve helped try to untangle it by slowly introducing Spring.

I’d rather have it, with its organization and standard patterns, than the Wild West of whatever any programmer or junior decided to do over the last 15 years and how that has evolved. In a complex application with lots of programmers coming and going I find it a net benefit.