Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composition vs Inheritance and GUI toolkits

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?

like image 405
Anin Teger Avatar asked Dec 14 '25 11:12

Anin Teger


1 Answers

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.

like image 173
Gishu Avatar answered Dec 17 '25 00:12

Gishu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!