|
| |
Good Programming Practices
- Group members my member access modifier (public, private,
etc) in a class definition for clarity and readability.
- Always define a class so its instance variables are maintained in a
consistent state.
- Initialize instance variables of a class in that class' constructor.
- List the private instance variables of a class first so as you read
the code, you see the names and types of the instance variables before they
are used in the methods of the class.
- List all the private members of a class first in one group and list
all the public members in another group.
- When appropriate (almost always), provide a constructor to ensure that
every object is properly initialized with meaningful values.
- Every method that modifies the private instance variables of an object
should ensure that the data remains in a consistent state.
- Avoid using method parameter names that conflict with class member names.
- Using this can increase program clarity in some contexts.
- Always invoke static methods using the class name and the dot
operator (.). This emphasizes to other programmers reading your code that he
method being called is a static method.
Source: Deitel, H.M. and Deitel P.J. Java: How to Program. 3rd ed. Upper Saddle River, New
Jersey. Prentice Hall.1999.
ISBN 0-13-012507-5, p 377.
|