Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied Code,Project Standards and Spring boot Application tuning. #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nishikant-tayade
Copy link

I have made the changes to the code considering the standards and tuning:

Spring Dependency Injection Standards:

  • Constructor Based Dependency Injection should be used, instead of Field Injection, as it helps during testing for creation of mocking objects. Also if we identify that there are lots of dependencies that we are injecting through Constructor this possibly means that our class is doing too many things and not following the SRP(Single Responsibility Principle).

  • By default the Spring beans are eagerly initialized but some beans/dependencies are better to be injected only when they are required,for ex: EmailService bean is not required unless and until there is requirement to send the mail, hence @lazy should be used.

Code standards:

  • Instead of creating an object every time,it is better to create an method that will provide that object as needed, like factory,for
    ex As ModelAndView is created every time controller, we can declare a method will provide the ModelAndView on basis of parameters, for which concepts like Method Overloading can be used.

  • Constants should be used for view name and for request mapping path because if in the future view name changes, and if you have used it multiple time like admin/product/add, then we have to make changes add only one place.

Minor Code Changes/Best Practices:

  • Instead of using Optional with isPresent() and get() combination, try to use other combinations as isPresent() and get() combination forces you to write the same code as if null handling.

I would also like to add:

  1. Flyway db migration
  2. Spring Data JPA Standards.

Thanks you:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant