Jtest logo




Contents  Previous  Next  Index

CODSTA.UCC


Utility classes should only have "private" constructors

Description

This rule flags any utility class that has non-"private" constructors.

A utility class only contains static methods and static variables. Because the utility class is not designed to be instantiated, all of the constructors should be private.

Example

 package CODSTA;
          
 public class UCC {
          
     public static String s = "UCC";
          
     public UCC() {} // violation
         
     public static String getUCC() {
         return "UCC";
     }
 }

Repair

 package CODSTA;
          
 public class UCC {
          
     public static String s = "UCC";        
     private UCC() {}
          
     public static String getUCC() {
         return "UCC";
     }     
 }

Reference

Bloch, Joshua. Effective Java Programming Language Guide. Addison Wesley, 2001, pp 89 - 90.


Contents  Previous  Next  Index

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