Refactoring - Inline Method
Motivation: A method's body is just as clear as its name.
public float GetMovieRanking(float rating, int totalVotes, int minVotesRequired, float meanVotes)
{
return CalculateMovieRanking(rating, totalVotes, minVotesRequired, meanVotes);
}
private static float CalculateMovieRanking(float rating, int totalVotes, int minVotesRequired, float meanVotes)
{
float movieRanking = (rating * totalVotes + minVotesRequired * meanVotes) / (totalVotes + minVotesRequired);
return movieRanking;
}
Refactor as:
public float GetMovieRanking(float rating, int totalVotes, int minVotesRequired, float meanVotes)
{
float movieRanking = (rating * totalVotes + minVotesRequired * meanVotes) / (totalVotes + minVotesRequired);
return movieRanking;
}
Comments
Post a Comment