News for hackers. Stuff that matters.
Re:You do not need inheritance with OOP by coldtea on Wednesday November 09, 2022 @05:19AM (#33529486)
No, but then you find out you don't need OOP either.
Re:You do not need inheritance with OOP by pjmlp on Wednesday November 09, 2022 @07:45AM (#33530752)
Dynamic dispatch and parametric polymorphism are also part of OOP.
Re:You do not need inheritance with OOP by coldtea on Wednesday November 09, 2022 @08:27AM (#33531259)
You can have both without OOP (at least not in the sense of a hierarchy of classes, or any C++/Java style), so...
Re:You do not need inheritance with OOP by pjmlp on Wednesday November 09, 2022 @10:25AM (#33532892)
"In the sense of a hierarchy of classes, or any C++/Java style)" is not the point of view of SIGPLAN, ACM or IEEE research about how a OOP language is supposed to be.

As a former OOPSLA attendee, I rather fallback on their opinion.

Re:You do not need inheritance with OOP by coldtea on Wednesday November 09, 2022 @11:55AM (#33534375)
>is not the point of view of SIGPLAN, ACM or IEEE research about how a OOP language is supposed to be.

Which is neither here, nor there. It's how OOP is thought of and practiced in real life by the statistically significant majority, so that's above what Alan Kay thought it should be or what SIGPLAN or the ACM or IEEE thinks "how an OOP language is supposed to be".

Terms take their meaning from actual mass usage, not from their inventors or what researchers think they should refer to.

Re:You do not need inheritance with OOP by karmakaze on Wednesday November 09, 2022 @12:29PM (#33534916)
I recognized the limitations of class- rather than object-based OOP early on and was glad to find out that's not what OOP was meant to be. Now I understand when people say OOP they mean class inheritance and not much else. Still useful for graphical widgets and some other places where inheritance works well.
Re:You do not need inheritance with OOP by pjmlp on Wednesday November 09, 2022 @01:37PM (#33535955)
Alan Kay defined one way of doing OOP, which was already a departure from Simula, and both of them are two measure data points on the OOP tree of language design.

Most mass users don't have PhD papers in language research, and whatever most think is wrong.

Re:You do not need inheritance with OOP by coldtea on Thursday November 10, 2022 @04:40AM (#33544229)
>Most mass users don't have PhD papers in language research, and whatever most think is wrong.

Not when it comes to language. In language what most people mean / refer to with a term is what the term means (not what the one who introduced the word meant, or what the etymology of the word is, or the "original meaning" and so on) - and people with PhD's in linguistics agree.

Re:You do not need inheritance with OOP by pjmlp on Thursday November 10, 2022 @01:30PM (#33550967)
There is what common people think they know about, and there is science.
Re:You do not need inheritance with OOP by mrkeen on Wednesday November 09, 2022 @05:51AM (#33529713)
I have a common personal use-case for inheritance:

If I'm forced to use a framework that infects my whole codebase, e.g. Spring, it's often possible to escape the infection by splitting a Service into a SpringService and a LogicService. LogicService thereby remains testable and doesn't depend on Spring. The way to connect them is to have the SpringService inherit from the non-spring service.

That said, I'd rather have neither Spring nor inheritance.

Re:You do not need inheritance with OOP by oweiler on Wednesday November 09, 2022 @06:09AM (#33529823)
If you use constructor injection services are unit testable without touching Spring.
Re:You do not need inheritance with OOP by mrkeen on Wednesday November 09, 2022 @06:47AM (#33530207)
Then can I remove those imports?
Re:You do not need inheritance with OOP by _boffin_ on Wednesday November 09, 2022 @10:42AM (#33533176)
Mock the dependencies in the constructor and test.

Why are you talking about removing imports?

Re:You do not need inheritance with OOP by mrkeen on Thursday November 10, 2022 @01:00PM (#33550508)
I do use constructors.

I'm refuting the claim that my unit tests won't touch Spring.

If my unit tests don't touch the Spring stuff in my class, either my unit tests on that class are woefully incomplete, or I didn't need the (explicit, directly-coupled) Spring stuff in my class.

Re:You do not need inheritance with OOP by coutego on Wednesday November 09, 2022 @06:03AM (#33529770)
It's funny how times have changed. Spring used to be that (micro)framework that prevented your code to depend on anything framework related. And here we are now...

I have been avoiding inheritance like the plague since at least 15 years ago and enjoying the pleasure of working with Spring for the same amount of time, approximately. But nowadays looking at what people do with Spring makes me extremely sad. Every time I find people "injecting" things by using annotations I can just think "WFT? Haven't we learnt /anything/?"

Re:You do not need inheritance with OOP by mrkeen on Wednesday November 09, 2022 @06:41AM (#33530148)
No, nothing's changed. Spring still infects your whole codebase. Just look at the imports, or try to run your code via a different framework if you think I'm exaggerating.

It's proponents still make the same claims about it protecting you from coupling, not causing it.

Re:You do not need inheritance with OOP by coutego on Tuesday November 15, 2022 @08:18AM (#33608769)
Spring does not need to infect your codebase. You can use the container without importing anything from Spring in other than one class (the one bootstrapping the system).

If you want to use Spring classes in the implementation of your clases then yes, you will need to import them. But this is no different than any other library.

If you just use XML configuration files (or use @Configuration) you don't (shouldn't) use @Inject, @Autowire and all other abominations. Or at least you didn't need, last time I checked a couple years ago. All your code is clear, free of any Spring code (unless you use some of the libraries) and fully reusable, testable, etc.

Why everyone moved to annotations for "dependency injection" (that crap is NOT DI!!!!!), not only in Java, but Python, Typescript, etc. I just can't understand. It can't only be the convenience of doing so by saving some keystrokes, but I just can't get it. We solved the modularity beautifully with Spring (and other DI engines) and then we proceed to throw away the solution and recreate the problem again? Get off my lawn...

Re:You do not need inheritance with OOP by deafpolygon on Wednesday November 09, 2022 @09:19AM (#33531905)
Taking the animal example here... if you do it the way the author suggested, then would the semantic meaning of $cat, $dog, $cow be lost somehow? (In that they're all an Animal). If you later on realized that $cat needed to do something special (i.e. have the graceful_landing property that no other animal has) - how is that done?

Just wondering - I'm a newbie at OOP :)

Re:You do not need inheritance with OOP by karmakaze on Wednesday November 09, 2022 @12:33PM (#33534971)
You can introduce intermediate classes: Animal > GracefulAnimal > Cat. The problem is if there's other branches that are also graceful that there's no way to include just the right subset. That's where composition is better in that a Graceful aspect can be mixed-in.

It's basically the same problem of categorizing with labels in a single tree structure. You often find you want to group lower subtrees without including their parent nodes. That's why Gmail labels are better than normal email folders.