Java Reference
In-Depth Information
Design Guidelines
A. Design Preparation
1. The ultimate guideline is to develop a clean design. Think before you start
coding. A working program is not necessarily a good program.
2. Express and document your design with consistent, clear notation.
B. Structured Programming
1. Do not use the continue statement.
2. Use the break statement only to terminate cases of a switch statement.
3. Have only one return statement in a method as the last line, unless it
unnecessarily complicates the method.
C. Classes and Packages
1. Do not have additional methods in the class that contains the main method.
2. Define the class that contains the main method at the top of the file it is in,
followed by other classes if appropriate.
3. If only one class is used from an imported package, import that class by
name. If two or more are imported, use the * symbol.
D. Modifiers
1. Do not declare variables with public visibility.
2. Do not use modifiers inside an interface.
3. Always use the most appropriate modifiers for each situation. For example,
if a variable is used as a constant, explicitly declare it as a constant using
the final modifier.
E. Exceptions
1. Use exception handling only for truly exceptional conditions, such as
terminating errors, or for significantly unusual or important situations.
2. Do not use exceptions to disguise or hide inappropriate processing.
3. Handle each exception at the appropriate level of design.
F. Miscellaneous
1. Use constants instead of literals in almost all situations.
2. Design methods so that they perform one logical function. As such, the
length of a method will tend to be no longer than 50 lines of code, and
usually much shorter.
3. Keep the physical lines of a source code file to less than 80 characters in
length.
4. Extend a logical line of code over two or more physical lines only when
necessary. Divide the line at a logical place.
 
Search WWH ::




Custom Search