Refactoring Techniques

Composing Methods
Much of refactoring is devoted to correctly composing methods. In most cases, excessively long methods are the root of all evil. The vagaries of code inside these methods conceal the execution logic and make the method extremely hard to understand—and even harder to change.
重构的大部分工作是正确地组合方法。在大多数情况下,过长的方法是所有问题的根源。这些方法内部代码的模糊性掩盖了执行逻辑,使方法极难理解,甚至更难修改。
The refactoring techniques in this group streamline methods, remove code duplication, and pave the way for future improvements.
该组中的重构技术简化了方法,消除了代码重复,并为未来的改进铺平了道路。

Moving Features between Objects
在对象之间移动特征
Even if you have distributed functionality among different classes in a less-than-perfect way, there is still hope.
即使你在不同类之间分配功能的方式不够完美,仍然有希望。
These refactoring techniques show how to safely move functionality between classes, create new classes, and hide implementation details from public access.
这些重构技术展示了如何在类之间安全地移动功能、创建新类以及隐藏实现细节以避免公共访问。

Organizing Data
These refactoring techniques help with data handling, replacing primitives with rich class functionality. Another important result is untangling of class associations, which makes classes more portable and reusable.
这些重构技术有助于数据处理,用丰富的类功能替换原始类型。另一个重要的结果是理清类的关联,使类更具可移植性和可重用性。
- Change Value to Reference
将值更改为引用 - Change Reference to Value
将引用更改为值 - Duplicate Observed Data 重复观测数据
- Self Encapsulate Field
- Replace Data Value with Object
用对象替换数据值 - Replace Array with Object
用对象替换数组

Simplifying Conditional Expressions
简化条件表达式
Conditionals tend to get more and more complicated in their logic over time, and there are yet more techniques to combat this as well.
条件句的逻辑随着时间的推移往往变得越来越复杂,还有更多的技术来应对这一问题。

Simplifying Method Calls
These techniques make method calls simpler and easier to understand. This, in turn, simplifies the interfaces for interaction between classes.
这些技术使方法调用更简单易懂。这反过来又简化了类之间交互的接口。

Dealing with Generalization
处理泛化问题
Abstraction has its own group of refactoring techniques, primarily associated with moving functionality along the class inheritance hierarchy, creating new classes and interfaces, and replacing inheritance with delegation and vice versa.
抽象有其自身的一组重构技术,主要与沿类继承层次结构移动功能、创建新类和接口以及用委托替换继承或反之亦然相关。