Coupling Rules

These are rules which find instances of high or inappropriate coupling between objects and packages.

CouplingBetweenObjects

Rule counts unique attributes, local variables and return types within an object. An amount higher than specified threshold can indicate a high degree of couping with in an object

This rule is defined by the following Java class: net.sourceforge.pmd.rules.CouplingBetweenObjects

Here's an example of code that would trigger this rule:

			
    
      import com.Blah;
      import org.Bar;
      import org.Bardo;
      //
      public class Foo {
        private Blah var1;
        private Bar var2;
        //followed by many imports of unique objects

        void ObjectC doWork() {
           Bardo var55;
           ObjectA var44;
           ObjectZ var93;
           return something;
        }

        }
        
    
		

ExcessiveImports

A high number of imports can indicate a high degree of coupling within an object. Rule counts the number of unique imports and reports a violation if the count is above the user defined threshold.

This rule is defined by the following Java class: net.sourceforge.pmd.rules.ExcessiveImports

Here's an example of code that would trigger this rule:

			
      
      import blah.blah.Bardo;
      import blah.blah.Hardo;
      import blah.blah.Bar;
      import blah.net.ObjectA;
      //imports over some threshold
      public class Foo {
        public void doWork() {}
      }
      
  
		

LooseCoupling

Avoid using implementation types (i.e., HashSet); use the interface (i.e, Set) instead

This rule is defined by the following Java class: net.sourceforge.pmd.rules.design.LooseCoupling

Here's an example of code that would trigger this rule:

			
  
  import java.util.*;
  public class Bar {

   // should be "private List list"
   private ArrayList list = new ArrayList();

   // should be "public Set getFoo()"
   public HashSet getFoo() {
    return new HashSet();
   }
  }