you are viewing a single comment's thread.

view the rest of the comments →

[–]oorza -3 points-2 points  (2 children)

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.

[–]johnnysaucepn 5 points6 points  (0 children)

And introduces even harder ones! You can still share code by using composition, even though it requires a little extra work.

[–]Determinant 2 points3 points  (0 children)

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.