views:

38

answers:

1

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?

+1  A: 

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.

Gishu
No problem. I was just curious if there was an example. I suppose there isn't and your answer makes sense.
Anin Teger