DEV Community

Discussion on: The Spring illness to Java developers

Collapse
 
nfrankel profile image
Nicolas Fränkel

Are you really advocating for static methods? If yes, as you wrote:

Oh God, kill me now

If no, then your writing is pretty confused (or confusing).

  1. You don't need annotations to make a class a component. That's actually a bad way to go.
  2. You can keep the same classes, but don't register them all in the beans factory

Here's an old post of mine: The case for Spring inner beans. Nowadays, you can replace the XML with a configuration class. This way, you can keep a a testable design at every step, and register only the beans you want in the factory.

Collapse
 
_fpineda profile image
Fernando Pineda

Hello @nfrankel , thanks for your comment. I have been following you long time ago.

Yes, I advocate for static methods, that's the point of my article.

The expression:
"Oh God! 🤦 ¡Kill me now!" is because of the ugly test and design of using every class as a @Component

Collapse
 
nfrankel profile image
Nicolas Fränkel

I have been following you long time ago.

Thanks! But then, you know I cannot agree with you on static methods.

The cost of creating an instance method instead of a static method is marginal, and the benefit is that you can test its callers in isolation. If you feel it doesn't deserve such test, fine. But you might change your mind later, the software will evolve so you'll need to test it later, etc.

The only thing I agree with is to stop making every class a Spring bean.

Finally, avoid annotations when you can and don't use autowiring a.k.a. magic.

Thread Thread
 
_fpineda profile image
Fernando Pineda

Well, Nicolas, that's ok. I think it depends. If the static method has a bit of complexity that's better to do an Instance method to test it isolated, but if it's just a bypass like a method in the example and that's my point (My bad 👎, I didn't make it clear) on that kind of methods that don't do a complex functionality it's better to do just a static method.

Thanks for your comments.