简体   繁体   English

弃用一组相关方法的最佳做法是什么?

[英]What's the best practice for deprecating a set of related methods?

I want to deprecate a method. 我想弃用一个方法。 It calls some helper methods which are now obsolete, and is exercised in several places by tests which are also now obsolete. 它调用了一些现在已经过时的辅助方法,并且通过现在​​已经过时的测试在几个地方运行。 In other words, I have a set of related methods / classes / tests across the project which are all part of the same deprecation and should be removed at the same time. 换句话说,我在整个项目中有一组相关的方法/类/测试,它们都是同一个弃用的一部分,应该同时删除。

When I come back later and try to delete the top-level method, how can I be sure I've found all the related stuff? 当我稍后回来尝试删除顶级方法时,我怎么能确定我找到了所有相关的东西? Obviously, I can just keep my own notes somewhere that tell me what related methods to remove. 显然,我可以在某处保留自己的笔记,告诉我要删除哪些相关方法。 Failing that, I can 1) delete the endpoint, 2) look for failing tests and remove them, and 3) rely on the IDE to find methods that are now unused and remove those too, but that seems error-prone to me. 如果做不到这一点,我可以1)删除端点,2)寻找失败的测试并删除它们,3)依靠IDE来查找现在未使用的方法并删除它们,但这似乎容易出错。

Is there a standard practice for deprecating a set of related methods / classes / tests to ensure they will all be removed simultaneously at a later date? 是否有一种标准做法来弃用一组相关的方法/类/测试,以确保它们将在以后同时被删除?

The best practice is to use some kind of project / issue tracking- 最佳做法是使用某种项目/问题跟踪 -

create a task (for example: JIRA-224) and write what should be replaced and how. 创建一个任务(例如:JIRA-224)并写下应该替换的内容以及如何替换。

add a comment to all the methods: 为所有方法添加注释:

/**
 * method that does nothing
 *
 * @deprecated will be removed in JIRA-224.  
 */
@Deprecated
public void old() {
// .....
}

when you are ready, the person that assigned to do the task can search "JIRA-224" in all the files and remove the methods. 准备好后,分配执行任务的人员可以在所有文件中搜索“JIRA-224”并删除方法。

Use @java.lang.Deprecated on method. 在方法上使用@java.lang.Deprecated Don't forget about javadoc : 不要忘记javadoc:

/**
 * Does some thing .
 *
 * @deprecated use {@link #new()} instead.  
 */
@Deprecated
public void old() {
// ...
}

I am not aware of a specific practice or even tool for that. 我不知道具体的做法甚至是工具。 Where: tools such as eclipse can easily give you warnings for unused private methods. 其中:诸如eclipse之类的工具可以轻松地为未使用的私有方法提供警告。

Anyway, I would suggest to simply "take notes". 无论如何,我建议简单地“做笔记”。 Meaning - open a defect in your bug tracking system and simply list the methods and tests you later intend to delete. 含义 - 在您的错误跟踪系统中打开一个缺陷,只需列出您稍后要删除的方法和测试。 So you have a single place that outlines your plan. 所以你有一个地方可以概述你的计划。

And as said: there are tools that tell about unused methods. 如上所述:有一些工具可以告诉我们未使用的方法。 Simply run the tool prior deleting the deprecated methods. 只需在删除已弃用的方法之前运行该工具。 Run it again afterwards - and then work the new messages that got added when running the tool again. 之后再次运行它 - 然后再次运行工具时添加的新消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM