Afferent Coupling of a Field (Incoming Dependencies)

The afferent coupling of a field is the number of callables (methods or constructors) that access it.

Since we only count direct accesses, this number ought to be low: if it is high, then encapsulating the field via accessor methods is called for.

Pre-packaged Query

Query name = "Semmle/Metrics/Fields/

Reports fields with an afferent coupling greater than 15.

from MetricField f, int n
where f.fromSource() 
      and 
      n=f.getAfferentCoupling()
      and
      n > 15
select f, n order by n desc

.QL Source of Metric

This metric is defined in MetricField:

   int getAfferentCoupling() {
      result = count(Callable m | m.accesses(this))
   }

References

Martin Fowler. Encapsulate Field Refactoring .

Patrick Smacchia. NDepend: Afferent Coupling at Field Level . 2007.

Digg!Reddit!Del.icio.us!Facebook!Slashdot!Technorati!StumbleUpon!Ma.gnolia!

Comments
Only registered users can write comments!
 
< Prev