And I think the real answer is yes. Inheritance is very nice in the API for GUIs. I've never seen the idea applied usefully elsewhere, though I'm sure there are examples.
And I think the real answer is yes. Inheritance is very nice in the API for GUIs. I've never seen the idea applied usefully elsewhere, though I'm sure there are examples.
Inheritance is a fundamentally flawed concept in type systems. It suffers from the fragile base class problem. Josh Bloch, writer of Effective Java, recommends using composition over inheritance. If you want inheritance so that you can selectively override event handlers, and fall back on default implementations... you want something that's broken, because that suffers from the fragile base class problem. You need a guarantee that the superclass you are overriding won't call your subclass methods in an unexpected way... in other words, you need implementation details. A better way is to explicitly call default handlers on the superclass.
I don't follow the last two sentences.
You can have addToWindow take any element, there just has to be a function called 'asElement' which will take your type and produce a relevent 'element' data structure. Further, you can use Haskell-style type classes or ML-style functors to make this easy and polymorphic.