Chapter 12Dealing with Inheritance

In this final chapter, I’ll turn to one of the best known features of object-oriented programming: inheritance. Like any powerful mechanism, it is both very useful and easy to misuse, and it’s often hard to see the misuse until it’s in the rear-view mirror.

Often, features need to move up or down the inheritance hierarchy. Several refactorings deal with that: Pull Up Method (350), Pull Up Field (353), Pull Up Constructor Body (355), Push Down Method (359), and Push Down Field (361). I can add and remove classes from the hierarchy with Extract Superclass (375), Remove Subclass (369), and Collapse Hierarchy (380). I may want to add a subclass to replace a field that I’m using to trigger different behavior based ...

Get Refactoring: Improving the Design of Existing Code now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.