51
you are viewing a single comment's thread
view the rest of the comments
[-] henfredemars@infosec.pub 7 points 1 month ago

I’ve seen some surprisingly fragile OOP solutions that require tons of internal knowledge about how the classes work. It seems to be a popular approach to writing code that just isn’t very flexible.

[-] nous@programming.dev 5 points 1 month ago

It requires you model your problem perfectly from the start, then it can work alright. But in reality you cannot know the future and when new requirements come in that don't fit the model you created you are left in a crappy spot of needing to refactor everything or just cram it in however you can.

[-] henfredemars@infosec.pub 5 points 1 month ago* (last edited 1 month ago)

I recently did some refactoring with injector and composition patterns already there and it was a breeze.

OOP isn’t bad but like anything it requires some care.

[-] nous@programming.dev 3 points 1 month ago

Note that I am explicitly calling out inheritance here rather than OOP as a whole. There are many things about OOP that are not that bad or quite ok, like composition for instance. It is generally badly designed inheritance that leads to

require tons of internal knowledge about how the classes work

And it is very hard to create a good inheritance structure that does not devolve over time as new requirements get added. While there are other patterns that OOP languages have started to adopt in more recent years (like composition and interfaces) that solve a lot of the same problems but in a vastly more maintainable way.

[-] MajorHavoc@programming.dev 3 points 1 month ago* (last edited 1 month ago)

is very hard to create a good inheritance structure that does not devolve over time as new requirements get added

That's such an important point. Whatever else folks take from this thread, I hope they catch that.

And I'll pile on to add - more layers is more risk. One layer of inheritance is a lot easier to keep maintaining than inheritance that goes four layers deep.

[-] nous@programming.dev 2 points 1 month ago

And if you only have one layer then why not just use interfaces/traits? Which are a vastly better design than inheritance.

this post was submitted on 10 Oct 2024
51 points (85.9% liked)

Programming

17314 readers
27 users here now

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



founded 1 year ago
MODERATORS