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).
You don't need annotations to make a class a component. That's actually a bad way to go.
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.
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.
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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Are you really advocating for static methods? If yes, as you wrote:
If no, then your writing is pretty confused (or confusing).
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.
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
Thanks! But then, you know I cannot agree with you on
staticmethods.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.
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.