This view comes from refactoring-----Improving the design of existing code
A method ' s just as clear as its name. 02
Put the "method" into the body of its callers and remove. 03
int getrating () {return
(Morethanfivelatedeliveries ())? 2:1;
}
Boolean morethanfivelatedeliveries () {return
_numberoflatedeliveries > 5;
}
04
int getrating () {return
(_numberoflatedeliveries > 5)? 2:1;
}
Motivation05
A theme of this book are to-use short methods named to show their intention, because these methods leads to clearer and easi Er to read code. But Sometimes you to come across a method in which the "body is as clear as" name. Or you refactor the "code into something" is just as clear as the name. When this happens, your should then get rid of the method. Indirection can be helpful and but needless indirection is irritating. 06
Another time to use Inline the ' when ' you have a group of methods that seem badly factored. Can inline them all into one and then reextract the methods. Kent Beck finds it is often good to does this before using Replace method and method Object. You inline the "various calls made by the" method "have behavior you want to have in the" Method object. It's easier to move one of the than to move the and It called methods. 07
I commonly use Inline the When someone are using too much indirection and it seems this every method does simple Delegat Ion to another method, and I get lost the delegation. In these cases some of the indirection are worthwhile, but not all of it. By trying to inline I can flush out the useful ones and eliminate the rest. Mechanics 08
Check that this method is not polymorphic. Don ' t inline if subclasses override the method; They cannot override a method of that isn ' t there.
Find all calls to the method.
Replace each call with the ' method ' body.
Compile and test.
Remove the method definition. 09
Written this way, the Inline method was simple. In general it isn ' t. I could write pages on "How to handle recursion", multiple return points, inlining into another object while you don ' t have a Ccessors, and the like. The reason I don ' t is that if you encounter these complexities and you shouldn ' t does this refactoring.