Extracting methods
Extracting methods is arguably one of the most common aspects of refactoring. In general, it is the process of taking a block of code, which specializes in a specific task, outside of the current context it is being used in and converting it into a method/function.
Doing this is generally good practice in programming and has the advantages of readability and extendibility. For example, by moving a specific block of code into its own method/function, that logic can be reused in other places in the program, without the programmer having to copy and paste that block of code. Having some functionality that is used a lot through a program inside a separate function is intuitively a good way to structure your code as well.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access