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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With