3

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?

Anin Teger
  • 157
  • 1
  • 5

1 Answers1

1

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.

Community
  • 1
  • 1
Gishu
  • 134,492
  • 47
  • 225
  • 308