hts.StevenWood.com

[ Last Page ]

Good Programming Practices

  1. Group members my member access modifier (public, private, etc) in a class definition for clarity and readability.
  2. Always define a class so its instance variables are maintained in a consistent state.
  3. Initialize instance variables of a class in that class' constructor.
  4. 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.
  5. List all the private members of a class first in one group and list all the public members in another group.
  6. When appropriate (almost always), provide a constructor to ensure that every object is properly initialized with meaningful values.
  7. Every method that modifies the private instance variables of an object should ensure that the data remains in a consistent state.
  8. Avoid using method parameter names that conflict with class member names.
  9. Using this can increase program clarity in some contexts.
  10. 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. 

[Last Page]
All material on this site is copyright © 1997- by Steven Wood or as credited. All right reserved. Use of this site indicates you agreement with the  terms of use.
Send comments or questions to about this page.
Every attempt has been made to credit work under copyright. If there are any claims that copyright has been missed please contact the .
+SDG+