News for hackers. Stuff that matters.
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.