Inline Method
(2 intermediate revisions by 2 users not shown) | |||
Line 3: | Line 3: | ||
Sometimes the body of a method is as clear as the method name. Replacing the method call with the body of the method can help get rid of needless indirection.<br> | Sometimes the body of a method is as clear as the method name. Replacing the method call with the body of the method can help get rid of needless indirection.<br> | ||
Another time to use the inline method is when you have a group of badly factored methods. By using the inline method you can construct one big method then reextract the methods. | Another time to use the inline method is when you have a group of badly factored methods. By using the inline method you can construct one big method then reextract the methods. | ||
+ | |||
+ | == Automatic Inlining == | ||
+ | |||
+ | An Inline Method can also refer to automated inline functionality in some languages. For example in C++ a method can be declared using the inline keyword. A method declared inline will upon complication be copied into the locations it is called from. This reduces overhead by eliminating function calls but increases binary size. Inlines are often used in high performance low level code. | ||
==References== | ==References== | ||
* [http://sourcemaking.com/refactoring/inline-method sourcemaking.com] | * [http://sourcemaking.com/refactoring/inline-method sourcemaking.com] |
Latest revision as of 03:22, 25 November 2010
This is basically the opposite of the Extract Method where you replace method calls with the body of code
Sometimes the body of a method is as clear as the method name. Replacing the method call with the body of the method can help get rid of needless indirection.
Another time to use the inline method is when you have a group of badly factored methods. By using the inline method you can construct one big method then reextract the methods.
Automatic Inlining
An Inline Method can also refer to automated inline functionality in some languages. For example in C++ a method can be declared using the inline keyword. A method declared inline will upon complication be copied into the locations it is called from. This reduces overhead by eliminating function calls but increases binary size. Inlines are often used in high performance low level code.