While I mostly agree with your conclusions and those from the comments (composition over inheritance; duplication is cheaper than the wrong abstraction; ...), I find the example with Rectangle & Square quite misleading.
Your Rectangle class clearly has a problem with the abstraction level: why should it offer methods like setWidth & setLength? Make it immutable (get rid of the setters) & be happy with not having to implement getArea twice. I think that's one of the strengths of OOP, so promoting to not use it feels odd to me.
Otherwise, thanks for making people think twice about this topic and happy holidays as well 😊
I also don't like most examples and this one is no different.
I personally prefer to go functional and not deal with classes but you can't always avoid it, not to mention that sometimes you do need to open the way to resize it (or the real world equivalent to whatever class you're dealing with).
When you do... you might find yourself with problems, or a lot of ifs here and there or even basically overriding the whole class to fit the needs.
I'm not saying not to use it, but that sometimes you can't just assume programming and real life abstract things the same way.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
While I mostly agree with your conclusions and those from the comments (composition over inheritance; duplication is cheaper than the wrong abstraction; ...), I find the example with Rectangle & Square quite misleading.
Your Rectangle class clearly has a problem with the abstraction level: why should it offer methods like setWidth & setLength? Make it immutable (get rid of the setters) & be happy with not having to implement getArea twice. I think that's one of the strengths of OOP, so promoting to not use it feels odd to me.
Otherwise, thanks for making people think twice about this topic and happy holidays as well 😊
I also don't like most examples and this one is no different.
I personally prefer to go functional and not deal with classes but you can't always avoid it, not to mention that sometimes you do need to open the way to resize it (or the real world equivalent to whatever class you're dealing with).
When you do... you might find yourself with problems, or a lot of
ifs here and there or even basically overriding the whole class to fit the needs.I'm not saying not to use it, but that sometimes you can't just assume programming and real life abstract things the same way.