In this post I want to show other practice which works in other way then Extract Method technique.
It is called Inline Method.
As usual I will show example for understanding.
This is simple example which has several simple methods:
/**
* This example shows how to use "Inline method" technique
* @author The Developer's Info
*
*/
public class InlineMethodExample {
public static void main(String[] args) {
String sum = getTextSum();
System.out.println(sum);
}
/**
* Method return text representation of sum
* @return text representation of sum
*/
private static String getTextSum() {
int value = getSum();
String sumText = getString(value);
return sumText;
}
/**
* Returns sum of 10 + 10
* @return sum value
*/
private static int getSum() {
int sum = 10 + 10;
return sum;
}
/**
* Method converts sum from int to string representation
* @param value
* @return converted from int to String sum value
*/
private static String getString(int value) {
return Integer.toString(value);
}
}
As you can see it is very simple example. Okay.
Now let’s look to these methods. As you can see all these methods we can move to one instead of using several small or as you want short methods.
At this point we can use Inline Method technique
/**
* This example shows how to use "Inline method" technique
* @author The Developer's Info
*
*/
public class InlineMethodExample {
public static void main(String[] args) {
System.out.println(getStringSum());
}
/**
* "Inline Method" technique
* @return text representation of sum
*/
private static String getStringSum() {
int value = 10 + 10;
return Integer.toString(value);
}
}
What I did?! I put(inline) in getStringSum bodies of getSum() and getString() methods.
Sometimes need to inline some functionality in one method or block of code instead of using external methods.
It is very great that we can use Extract Method technique for extracting functionality to external methods, but sometimes you can find or write code with a lot of methods which need to be on the one method and here you will find useful Inline Method technique.
If you’d like to get the latest posts as soon as they’re published, subscribe to website’s feed!

Hey! Is it OK that I go a bit off topic? I am trying to view your post on my Blackberry but it doesn’t display properly, do you have any suggestions? Thank you for the help I hope! Carlos
[Translate]
Hi Carlos.
It seems that this simple theme doesn’t show properly in smartphones. I will check it.
Thanks for notification
[Translate]