2

Using PMD 5.4.2 for JAVA code,seen some violation related to Possible God Class, like below:

Possible God class (WMC=69, ATFD=65, TCC=0.03218390804597701)

I don't want to suppress these warning. So can anyone explain me,what will be best workaround to fix this violation.

Thanks for explanation.

Muhammad Shahzad
  • 9,340
  • 21
  • 86
  • 130
manoj
  • 131
  • 2
  • 8
  • Rewrite your code so your class is not as huge as it appears to be? See [this question](https://stackoverflow.com/questions/37389376/pmd-rule-god-class-understanding-the-metrics) for some more details about the metrics. – Ken Y-N Jun 14 '16 at 07:44
  • @Ken Y-N Just upgraded from older pmd 4.2 to pmd 5.4.2,have a large number of class,so not possible to rewrite the code . – manoj Jun 14 '16 at 07:47
  • 4
    @manoj If you don't want to suppress the warning or fix your code, what do you expect to do? – Kayaman Jun 14 '16 at 07:51
  • Well then, either downgrade or edit the PMD source code. – Ken Y-N Jun 14 '16 at 08:00
  • @Ken Y-N I think it just not depend upon the class size,because i have some class files,which have very less lines of code(around 100 lines). – manoj Jun 14 '16 at 08:16

2 Answers2

1

From http://pmd.sourceforge.net/pmd-5.0.1/rules/java/design.html

The God Class rule detects the God Class design flaw using metrics. God classes do too many things, are very big and overly complex. They should be split apart to be more object-oriented. The rule uses the detection strategy described in "Object-Oriented Metrics in Practice". The violations are reported against the entire class. See also the references: Michele Lanza and Radu Marinescu. Object-Oriented Metrics in Practice: Using Software Metrics to Characterize, Evaluate, and Improve the Design of Object-Oriented Systems

and some more to read on how to refactor god classes in How do you refactor a God class?

Community
  • 1
  • 1
Gerald Mücke
  • 10,724
  • 2
  • 50
  • 67
0

Split the class into few smaller classes (less methods, less other classes used). It will be easier to read the code also.

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115