Search code examples
javadeprecatedconventionsobsolete

Annotating methods with no implementation


In the interest of clean and beautiful code, I've been looking for an answer to a question that's popped up whist documenting my latest project.

Often times, there will be an abstract class or interface with methods requiring implementation; and occasionally, the class inheriting these methods have other specific and unique methods which make those inherited obsolete, and thus never referenced. To avoid adding functionality where functionality is not used, I've left these obsolete inherited methods empty, and commented on why they are so. Still, I feel that there's more I should do, but could not come up with an answer to what, other than to give it the deprecated annotation. This would ensure that anyone attempting to use the method would realize that it is not supported, and would therefore either use the more appropriate class specific alternatives, or add in the implementation. However, I've always thought of the deprecated annotation as belonging solely to content which was supported at one point, and is planned to be removed. Whereas in my case, the content has never been supported and has is not planned to be removed.

Would the deprecated annotation be appropriate here? Is there a more appropriate alternative? Or is it considered ill practice to leave these inherited methods without proper implementation, even if considered obsolete.

I appreciate your time and any possible feedback you may offer. Thank you, - Justis


Solution

  • The @deprecated annotation exists to notify users that certain methods will be removed in the future. The only reason for not removing them right away is that it would break existing code. In your case, it seems like your might be abusing inheritance. Extending from a class and not implementing the expected behavior is a code smell which is called Refused Bequest What is a Refused Bequest?