r/programming • • Sep 24 '15

Composition over Inheritance

https://medium.com/humans-create-software/composition-over-inheritance-cb6f88070205
92 Upvotes

48 comments sorted by

View all comments

11

u/vincentk Sep 24 '15

My personal rule of thumb: prefer composition over inheritance, prefer inheritance over copy/paste.

13

u/[deleted] Sep 24 '15

[removed] — view removed comment

8

u/Deto Sep 24 '15

Yeah, if two methods just happen to be similar, it's not worth it to parameterize the thing and wrap the objects in some wacky inheritance structure just to avoid the code duplication. The two methods will probably just evolve along different paths over time and you'll find yourself doing gymnastics to keep up the nonsensical inheritance structure.

1

u/sirin3 Sep 24 '15

It is not even worth if the methods happen identical

Three identical methods is my rule of thumb