没有实现的注释方法 [英] Annotating methods with no implementation

查看:76
本文介绍了没有实现的注释方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了获得简洁漂亮的代码,我一直在寻找一个问题的答案,而这个问题在记录我的最新项目时突然出现.

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.

感谢您的宝贵时间,以及您可能提供的任何反馈意见. 谢谢, -Justis

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

推荐答案

存在@deprecated注释是为了通知用户将来某些方法将被删除.不立即删除它们的唯一原因是,它将破坏现有代码. 就您而言,您似乎正在滥用继承.从类中扩展而未实现预期的行为是一种代码异味,称为拒绝行为 什么是拒绝遗赠?

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?

这篇关于没有实现的注释方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆