Extracting a method

Working with legacy code often involves working with very large methods. A large method is any method that is longer than twenty lines. Preferably, methods are kept as small as possible, even down to just a few lines.

A large method can mean that the code is violating the Single Responsibility Principle. What needs to be done is to find the seams in the method. Seams can be found by commenting the different sections of the method. Once you have commented the sections, you have identified the seams.

Seam
In code, this is the location where two pieces of business logic meet. Normally, you might refer to the location where the private method is called by a public method as a seam in the public method. The code has been stitched together at that location. In this case, there are no private methods, so we are identifying where we want the seams to be. 

Each one of those seams is probably a lower order method that can be extracted. In most editors and IDEs, highlight the code you want and use the extract method refactoring provided through either a right-click, context, menu, or via the menu bar.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.104.143