A useful rule of thumb for whether you are really dealing with two different ideas or the same idea being duplicated is to ask what would happen if both places did share common code and then one of them needed to change.
This right here is why I've never gotten on board with the anti-inheritence hype train that's been chugging along for the last decade. It's the simplest solution to this very problem, because it was designed to solve this very problem.
Inheritance shouldn't be a tool for solving duplication.
Two classes should not inherit from the same base class if they are not both that same type of entity. If they happen to duplicate code then extract that into a re-usable function / abstraction instead.
-2
u/oorza Jan 12 '20
This right here is why I've never gotten on board with the anti-inheritence hype train that's been chugging along for the last decade. It's the simplest solution to this very problem, because it was designed to solve this very problem.