Under the circumstances?
Are you discovered too lengthy code in your procedures for you or other people, which contains many things that are difficult to understand, so that you have to find this code is doing this, the code is to do that ... Do you actually appear in a method? ! When you have this feeling, you should consider whether this reconstruction is used.
OBJECTIVE: The name of the method can explain the meaning of the code it contains. Each method is smaller. What should be noted: The length of the code in a method is not the core problem. It is whether it can indicate what it wants to complete, such as a process of processing a user request method, it must first determine the user status, then receive the user request, then Is it possible to meet the user's needs, and finally returned to the user corresponding message. These codes seem to be too lengthy in one way, we can determine the user status, receive the user request to write in an independent method, and then call it in the processing method. And some time the code is very long, but you can't take a clear part of the code, forcibly extracting the anti-effect, so you must strengthen the clarity of the code and then do the extraction. How to use: 1. Create a new method, give it a clear naming (you must clearly indicate that the method use) 2, put the code to be extracted into a new method, modify (such as incoming some parameters) 3, check Temporary variables, add it to the method 4, see if returning value is required, reference this method 6, compile, test (the next article provides sample code) in the original code