Jtest logo




Contents  Previous  Next  Index

MISC.MSF


Avoid too many "static" fields

Description

This rule flags code that contains more than two "static" fields.

Static variables act global in non-OO languages. They make methods more context-dependent, hide possible side-effects, sometimes present synchronized access problems, and are the source of fragile, non-extensible constructions. Also, neither static variables nor methods can be overridden in any useful sense in subclasses.

Example

 package MISC;
 
 public class MSF {
     private static int s_size;    
     static String s_title;        // violation
 
     static void setFields (int size, String title) {
         s_size = size;    
         s_title = title;
     }     
 }

Repair

Try to minimize static fields if possible.

Reference

http://g.oswego.edu/dl/html/javaCodingStd.html


Contents  Previous  Next  Index

ParaSoft logo
(888) 305-0041 info@parasoft.com Copyright © 1996-2001 ParaSoft