Sasgorilla
Sasgorilla

Reputation: 3130

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.

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?

Upvotes: 4

Views: 1668

Answers (3)

user3761001
user3761001

Reputation: 128

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.

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.

Upvotes: 3

Jay Smith
Jay Smith

Reputation: 2480

Use @java.lang.Deprecated on method. Don't forget about javadoc :

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

Upvotes: 2

GhostCat
GhostCat

Reputation: 140505

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.

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.

Upvotes: 0

Related Questions