Extracting Methods

With the Extract Method operation, you can create (or extract) a new method from multiple lines of code, a single line, or an expression within a given line of code. In each case, the method is created immediately following the method from which the code was extracted. The extracted code is replaced by a call to the new method.

Listing 10.1 provides an example of a method that is unnecessarily long. We’ve added line numbers for reference purposes. When you’re reviewing code, methods such as these are common and exactly what you should be looking for. The method is designed as a static call that returns a given customer’s Order object based on the customer’s ID number and the order ID number. However, the order, the order line ...

Get Microsoft® Visual Studio® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.