Refactoring consists of improving the internal structure of an existing program's source code, while preserving its external behavior. 1
Refactoring is the process of improving the design and structure of existing code, without changing its functionality. It is a technique that helps developers to make their code more maintainable, readable, and extendable.
There are several reasons why refactoring is important:
- It makes code easier to understand: By improving the structure and organization of the code, refactoring makes it easier for developers to understand what the code is doing, and how to make changes to it.
- It makes code more maintainable: By improving the design of the code, refactoring makes it easier to add new features, fix bugs, and make other changes to the code without introducing new bugs.
- It makes code more scalable: By improving the structure of the code, refactoring makes it easier to add new features and to handle more complex requirements, without making the code more complex.
- It helps to remove code smells: Code smells are patterns in the code that indicate deeper problems, such as poor design or over-complicated logic. Refactoring helps to remove these code smells and improve the overall quality of the code.
Some examples of refactoring techniques include:
- Extracting methods or classes, so that the code is more modular and easier to understand.
- Renaming variables or methods, so that the code is more readable.
- Removing duplicated code, so that the code is more maintainable.
- Replacing large, complex switch statements with polymorphism or strategy pattern, so that the code is more extensible.
Refactoring is an ongoing process that should be integrated into the development workflow, and not just a one-time event.
- What is Refactoring? - Agile Alliance
- Refactoring — The Hygienic Habit
- Refactor Mercilessly - Extreme Programming (XP)
- The goal of refactoring During TDD - Test Driven Development (TDD)
|Refactoring: Improving the Design of Existing Code - As the application of object technology—particularly the Java programming language—has become commonplace, a new problem has emerged to confront the software development community. Significant numbers of poorly designed programs have been created by less-experienced developers, resulting in applications that are inefficient and hard to maintain and extend. Increasingly, software system professionals are discovering just how difficult it is to work with these inherited, non-optimal applications. For several years, expert-level object programmers have employed a growing collection of techniques to improve the structural integrity and performance of such existing software programs. Referred to as refactoring, these practices have remained in the domain of experts because no attempt has been made to transcribe the lore into a form that all developers could use... until now. In Refactoring: Improving the Design of Existing Software, renowned object technology mentor Martin Fowler breaks new ground, demystifying these master practices and demonstrating how software practitioners can realize the significant benefits of this new process.|