Back to Blog

Refactoring 1: Untangling and Decomposing a Messy Inheritance Hierarchy

#Life
  1. A messy inheritance hierarchy is a serious problem because it leads to duplicate code, which is the bane of a programmer's existence.

  2. Isn't this more classes than I had originally? How can this make my life easier? Often in life, you take a step back to move further forward. For a convoluted inheritance hierarchy, the extracted new inheritance hierarchy can almost always be dramatically simplified.

The importance of a function is not proportional to its size — and this is especially true in an inheritance hierarchy.

  1. It's not difficult to identify when "an inheritance hierarchy takes on two different responsibilities": If all classes at a particular level in the inheritance hierarchy have subclass names that start with the same adjective, then that inheritance hierarchy is very likely taking on two different responsibilities.