user2572526
user2572526

Reputation: 1279

How to check the inheritance level of a java class using tools as checkstyle, PMD, findbugs etc?

I'm developing a Java application using Netbeans and I'm trying to follow all the coding guidelines suggested by my company. To do that I installed some tools like Checkstyle, PMD and findBugs but I'm not an expert in those code quality analyzers and I don't know how to configure all the rules. In particular I don't know if there is a rule to check this requirement (given by my company): "Inherit level must be 6 or below. Long inheritance tree makes the code very difficult to read, understand, maintain and refactor. Most of inheritance cases can be covered by implementing an interface and using composition which is easier to maintain." Is there a manner to do this check? Tnx!

Upvotes: 0

Views: 420

Answers (1)

Kedar Parikh
Kedar Parikh

Reputation: 1271

Its a heavily debatable topic and 6 seems to be some sort of magic number that has been arrived at.
Anyways I dont think there are any standards or acceptable level for the depth of inheritance hierarchy and hence none of the tools or ide plugins would be able to help out of the box, however plugins like PMD support custom rules as long as you can write one yourself. Try and explore it.
In case you want something readymade, you can try a code thats here

Upvotes: 2

Related Questions