This is a story about how I gradually fell in love with composition
@asyncrosaurus@programming.dev
link
fedilink
English
12
edit-2
1Y

6First off, Inheritance is not “dead”. We all just learned to favour interface inheritance over class inheritance.

Secondly, class inheritance is not bad or useless, it’s just poorly taught and wildly overused. The fact that the article still uses the bullshit Animal kingdom example is indicative of that. There’s no value in trying to model cats and dogs in OOP.

Inheritance is pretty useful in niche scenarios, mostly involving polymorphism and probably in the context of Library or Framework code. Trying to re-use code between classes with inheritance is always the incorrect approach. Two classes that are unrelated but have similar properties don’t actually need a common base class, they can each have their own version of the data.

The big, big, big problem outside the education system comes back to the top down, design-first approach. There’s still this strange practice of trying to model class hierarchies and abstract classes in neat little diagrams before you’ve actually started writing code. No UML type document has ever survived contact with the real world. If you need any form of inheritance, it will become obvious as you build out your system.

Create a post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



  • 1 user online
  • 1 user / day
  • 1 user / week
  • 1 user / month
  • 1.11K users / 6 months
  • 1 subscriber
  • 1.21K Posts
  • 17.8K Comments
  • Modlog