O'Reilly logo

Refactoring: Improving the Design of Existing Code by Don Roberts, William Opdyke, Kent Beck, Martin Fowler, John Brant

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required