Refactoring a function

I have the following method :
//Here IdForAuth will be a userId who is member of the channelID so using its token
one can fetch the details of the channel
public Channel fetchChannelDetailsFromChannelId(String channelId, String IdForAuth) {
token = fetchToken(idForAuth)
Channels.getInfo(token, channelD);

Now is the signature for above method is fine.
Or could i do like fetchChannelDEtailsFromChannelId(String, String token) and directly use token

Please suggest your view about both ways

Rohit BajajAsked:
Who is Participating?
It depends on the design of the application and what the token is/where the token is used.

In the first case the token is local to the method (assuming that the token is not an instance variable) and it is only used internally to that method.
In the second case the token is obtained elsewhere and is used in the method.

Use the first case if you do not need to use the token anywhere else.
Use the second method if the token needs to be used in any other methods as well.

If the token is an instance variable and you need to initialise it right before obtaining channel details, then use the first case.
Pawan KumarDatabase ExpertCommented:
Will go with Method1.

Handle fetchToken in method itself.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.