- The scope of the method should be very clear (public / private / protected based on the requirement). This will be easy to identify if any changes in future for assessment.
- The method name and variable name should completely be relevant. Names representing methods must be verbs and written in mixed case starting with lower case (ex : getName, computeTotal)
- Method should not exceed 50 lines. If so, create a private method and have the logic there.
- Every method should have JavaDoc (comments) clearly with Javadoc conventions (ctrl + shift + j in eclipse will add comments. You need add some description about methods)
- Try..Catch (Catch exception should throw to the class to caller to capture the error and provide proper error message in the UI. Catch exception should not printStackTrace.
- Don't hardcode static number / strings. Use constants. Names representing constants (final variables) must be all uppercase using underscore to separate words. (ex : THIRD_PARTY_SOURCE => 'DFP')
- Names representing methods must be verbs and written in mixed case starting with lower case
- The name of the object is implicit, and should be avoided in a method name. (line.getLength(); // NOT: line.getLineLength();)
- is prefix should be used for boolean variables and methods (isFound, isDeleted, isSet)
- The term find can be used in methods where something is looked up
Friday, February 10, 2012
Coding guidelines for Method creation in Java
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment