It's said that composition is preferred over inheritance. Every single open source GUI toolkit however uses inheritance for the drawn widgets (windows, labels, frames, buttons, etc). I checked Qt, wxWidgets, and GTK+. Is there an example of a GUI toolkit (written in any language) that uses composition instead of inheritance to separate the various widgets?
What is the problem that you're facing with those GUI Toolkits ?
I think, They derive from a common Widget base class so that they all expose a minimum interface. So you could write code that can work with any SpecializedWidgetType. I think this is a good use of inheritance..
Prefer composition to inheritance.. but do not shoehorn composition where inheritance is the right answer. There are always exceptions to a rule/guideline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With