Best practices: use final wherever possible, constructor injection, this. access to fields #191
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Implementation of following best practices:
Every class should be final by default, except classes explicitly designed to be extensible. Unfortunately Spring beans cannot be final - http://stackoverflow.com/questions/2657432/make-spring-service-classes-final
Also method and constructor parameters, field and variables should be final. This is a no-brainer.
It is recommended to use constructor injection instead of field injection to provide better testability and safety against NPE. Every object should be fully initialized upon construction.
Using .this to access fields provide a safety against accidental use of parameter/variable, thus greatly reducing a number of possible bugs..
Supersedes: #153 #172
Resources:
http://whiley.org/2011/12/06/final-should-be-default-for-classes-in-java