Coupling Degree

The coupling degree is a measure of the intimacy of a dependency between two classes. Based on Hitz & Montazeri we proposed the following measure of coupling degree:

couplingDegree(A, B) =
   (instability(B) + access(A, B) + scope(A, B))/3

Where:

access(A, B) = # B members A references/# B members

scope(A, B) = # A members that reference B/# A members

For example, assume A and B belong to a package P that contains ten classes: A – J. Here's the declaration of B:

class B {
   private C c;
   private D d;
   public void service1() { ... }
   public void service2() { ... }
   void service3() { ... }
   protected void serivce4() { ... }
   private void service5() { ... }
}

Furthermore, assume B references classes C and D only.

Here's the declaration of A:

class A {
   private B b = new B();
   public void meth1() {
      B temp = new B();
      b.service1();
      temp.service2();
   }
   public void meth2() {
      b.service3();
   }
   public void meth3() {
      String msg = "Hello";
      System.out.println(msg);
   }
}

Clearly A depends on B. We can compute the intimacy of this coupling as follows:

cplDeg(A, B) =
   (instability(B) + access(A, B) + scope(A, B))/3

Where:

instability(B) = 2/10 (P has 10 classes but B only references 2)
access(A, B) = 3/7 (B has 7 members but A only uses 3)
scope(A, B) = 3/4 (A has 4 members but only 3 use B)

Adding and dividing we get:

(2/10 + 3/7 + 3/4)/3 = (.20 + .43 + .75)/3 = .46