You are previewing Refactoring: Improving the Design of Existing Code.

Refactoring: Improving the Design of Existing Code

Cover of Refactoring: Improving the Design of Existing Code by Don Roberts... Published by Addison-Wesley Professional
O'Reilly logo

Chapter 11. Dealing with Generalization

Generalization produces its own batch of refactorings, mostly dealing with moving methods around a hierarchy of inheritance. Pull Up Field (320) and Pull Up Method (322) both promote function up a hierarchy, and Push Down Method (328) and Push Down Field (329) push function downward. Constructors are a little bit more awkward to pull up, so Pull Up Constructor Body (325) deals with those issues. Rather than pushing down a constructor, it is often useful to use Replace Constructor with Factory Method (304).

If you have methods that have a similar outline body but vary in details, you can use Form Template Method (345) to separate the differences from the similarities.

In addition to moving function around ...

The best content for your career. Discover unlimited learning on demand for around $1/day.