2 ms·
Inheritance got a bad rap in part because object oriented analysis was done as an exercise in taxonomy (Employee is a Person is a Mammal is an Organism...), ins
by millstone 11y ago
Inheritance got a bad rap in part because object oriented analysis was done as an exercise in taxonomy (Employee is a Person is a Mammal is an Organism...), instead of identifying useful abstractions. A second problem is using inheritance when composition is obviously better. java.util.Stack is a lovely example of both sins in action.
Where inheritance shines is in enabling close coupling across module boundaries. An example is event routing: how do you enable customization of how events flow through your app? UIKit handles this through inheritance. The base method gives you the default behavior, which you can override to customize. You can stop propagation by just not calling super, or redirect the event by calling the method somewhere else, etc. It's flexible.
JavaScript handles this clumsily, by trying to anticipate all the customizations you might want to do and providing APIs for each of them (event.preventDefault, event.stopPropagation...) Despite all that, frameworks like React have to reimplement event dispatch, because the default behavior is too inflexible.
Here inheritance is the glue that enabled close coupling between UIKit's default event dispatch algorithm and outside modifications to it.
- jstimpfle 11y agoYeah widget toolkits (if not done across maintenance boundaries) are really the one situation which is always described as a good fit for inheritance. However I don't think I like the idea of "close coupling across module boundaries". Sounds like an antithesis to sustainable architecture to me. Anyway I don't do UI...