12

We are using the source code analyzer PMD in our Java project. I am trying to resolve the reported issues and I am currently struggling with the GodClass rule. I know that the idea is not to create huge classes.

However, I don't like the word "huge" because it's too vague. Can anybody explain how the metrics of this rule works? The report says e.g.

Possible God class (WMC=47, ATFD=11, TCC=0.06315789473684211)

What do all these numbers mean? Does anybody know the formula that decides whether a particular class is huge or not?

Javadoc to this rule states

The rule uses the detection strategy described in [1]. The violations are reported against the entire class. [1] Lanza. Object-Oriented Metrics in Practice. Page 80.

Well, I don't wont to order some book just because of its page 80.

Btw. is there a way to configure such rule, i.e. change its parameters?

Thanks for explanation.

Cimlman
  • 3,404
  • 5
  • 25
  • 35
  • Amazon lets you look inside that book (!) – Brian Agnew May 23 '16 at 11:14
  • 1
    I admit that I am not familiar with Amazon Look inside. I have tried it just now. It seems that I cannot look inside the full version of this particular book. Only the chapter Introduction is available. – Cimlman May 23 '16 at 11:49

2 Answers2

15

WMC stands for Weighted Methods Count or Weighted Method per Class. The WMC metric is defined as the sum of complexities of all methods declared in a class. This metric is a good indicator how much effort will be necessary to maintain and develop a particular class.

ATFD stands for Access to Foreign Data. This metric represents the number of external classes from which a given class accesses attributes, directly or via accessor-methods.

TCC stands for Tight Class Cohesion. TCC is the relative number of methods directly connected via accesses of attributes.

The code triggers a violation if WMC >= 47 and ATFD > 5 and TCC < 1/3.

You can read about the God class on page 55 in Object-Oriented Metrics in Practice (and you do not have to buy the book to just read 1 page). You can also read the PMD documentation.

Nathan
  • 8,093
  • 8
  • 50
  • 76
10
  • WMC = Weighted Methods Count
  • ATFD = Access To Foreign Data
  • TCC = Tight Class Cohesion

Baselines seems to be defined as constant values. If you would like to know more, you can find the implementation here. (A little older code, but it is all in one place here.)

Csuki
  • 1,297
  • 8
  • 21