Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is using the framework's features considered wrong

I joined a company as a junior developer and I get assigned to do maintenance and fixes to various applications.

In every project that I had to work in a team I always heard complains about my code being too "framework coupled" and that I should write the code using plain Java rather than using the Spring Framework’s features (heck, I even got yelled at for using @Autowired rather than Constructor Injection)

I am really frustrated by this thing and I want to know if I am in the wrong. Aren’t the framework’s features the main reason a programmer is going to use that framework?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Usually, the reasoning behind that way of thinking is that it would be easier to one fine day swap the Framework you use today to some other with the minimum required effort. You might argue that this isn’t something very common or that you do very often, but still, even if the reason does not convince you it is generally a good practice to try to decouple your code as much as possible from the underlying Framework for multiple reasons (in addition to the one just mentioned you also have unit testing made easier).

In regards to the @Autowired topic, constructor injection is usually preferred for two main reasons:

  1. You clearly define the dependencies for your class to work properly;
  2. It is easier to unit test it because mocking its dependencies is way easier if you can "inject" them via the constructor.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading