Extract Method

You have a code fragment that can be grouped together.Turn the fragment into a method whose name explains the purpose of the method.
 

Why:

First, it increases the chances that other methods can use a method when the method is finely grained.

Second, it allows the higher-level methods to read more like a series of comments.

Third, overriding also is easier when the methods are finely grained.

 

Notice:

First, small methods really work when you have good names.

Second, the key is the semantic distance between the method name and the method body. If extracting improves clarity, do it, even if the name is longer than the code you have extracted.

posted @ 2007-04-20 15:03  南守拥  阅读(175)  评论(0编辑  收藏  举报