3 ms·
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'
by deafpolygon 4y ago
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 :)
- karmakaze 4y agoYou 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.