Subclassing "Not inteded for subclassing"

Frank Benoit keinfarbton at
Tue Oct 14 13:41:21 PDT 2008

Simen Haugen schrieb:
> I see dwt also have the "Not intended for subclassing", but the classes
> are not marked final.
> It shouldn't be any problems subclassing as long as you're careful, right?
> Right now I want to subclass Text and automatically add a dynamic
> tooltip. The same type of text box should be used many places in my
> application. I know I can just bind each time, but is it really
> dangerous to do this kind of subclassing to save typing?
> Or is there a easier way to solve these kind of things?

Hehe, i don't know why, but i simply forgot about making them 'final'.
Perhaps i should do that :)
Well, some of them are subclassed within SWT, but they shall not be
subclasses by user code. (Decorations, Scrollable, ..)

I think, they are not intended for subclassing, because of ...
1. So you do not depend on protected/private API and the SWT project is
free in changing it in a future version.
2. So you do not used protected/private API which may be platform
dependent. There are examples of this.
3. So you do not accidentally change any behavior of the widget, which
might be expected from other classes, like layouts or widget containers.

I am convinced, the SWT devs are very good designers and they choose
this restriction for good reason.

Perhaps you can do this by composition instead of inheritance.
Do you have code examples of what you want to do?

More information about the Digitalmars-d-dwt mailing list