“Prefer composition over inheritance” is a popular saying amongst programmers. In this article, I want to demonstrate what that looks like. We’re going to refactor some Rails classes from inheritance to composition. Then we’ll refactor again from composition to something even better: data. Inheritance (The Original Code) In an attempt to show “real” code, I’ve taken this example from the Rails cod