views:

295

answers:

2

I have just installed PMD to analyze my Java project. Really nice tool, highly recommended. Anyways, I got a few errors saying:

"An empty method in an abstract class should be abstract instead"

I checked out PMD documentation and the explanation says:

as developer may rely on this empty implementation rather than code the appropriate one

So I think I understand the reason behind this code style error, but consider the following scenario: I have an abstract class called Entity. This class has a boolean method with default implementation. (controls whether to delete its related entities upon deletion). Only a few of the derived classes override this default behavior to true.

Should I remove the default implementation and force all deriving classes to declare their behavior? Do you really think this pattern is such a bad practice?

Clarification: PMD treats a method with single return statement as empty.

A: 

When your method has a default implementation, then it is not empty ? Or do I miss something ?

For me, an empty method looks like this:

public void EmptyMethod()
{}
Frederik Gheysels
well, PMD treats a method that only returns boolean or null as empty too
LiorH
+1  A: 

I think it's just a guideline. It tells you so that you might want to reconsider your design, but if your design already makes perfect sense, there's no reason to obey a software instead of your brain.

Mehrdad Afshari