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:
public class InlineMethodExample{public static void main(String[] args){String sum = getTextSum();System.out.println(sum)}private static String getTextSum(){int value = getSum();String sumText = getString(value);return sumText}private static int getSum(){int sum = 10 + 10;return sum}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
public class InlineMethodExample{public static void main(String[] args){System.out.println(getStringSum())}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!
No related posts.

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
Hi Carlos.
It seems that this simple theme doesn’t show properly in smartphones. I will check it.
Thanks for notification