Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [platform-swt-dev] Subclassing Widgets..


See Widget.checkSubclass().  Originally, the SWT widgets were final.  This method is a compromise.   If you are willing to accept the risk, go ahead. I suggest you read up on the "Fragile Superclass" problem, ignoring the static compile time issue which Java fixes, concentrating on the dynamic portion of the problem.

Subclassing is a great way to organize code within a library but a dangerous and inflexible way to ship an API. Classes must be designed with subclassing in mind or they rarely make sense to subclass and contain all kinds of subtle issues. In the case of SWT, given that the widget classes are completely different across platforms, the dangers are multiplied.  If you subclass a widget class in SWT that is not intended to be subclassed, then you are on your own.



"R.J. Lorimer" <rjlorimer@xxxxxxxxxxxxxxxx>
Sent by: platform-swt-dev-admin@xxxxxxxxxxx

11/23/2004 09:03 AM

Please respond to
platform-swt-dev

To
<platform-swt-dev@xxxxxxxxxxx>
cc
Subject
RE: [platform-swt-dev] Subclassing Widgets..





Eric,

Maybe I am wrong (I haven't tried for a long while), but I was under the
impression that runtime checks were in place that prevented subclassing in
many cases.

Is this not the case anymore?

-----Original Message-----
From: platform-swt-dev-admin@xxxxxxxxxxx
[mailto:platform-swt-dev-admin@xxxxxxxxxxx] On Behalf Of Eric Clayberg
Sent: Tuesday, November 23, 2004 7:38 AM
To: platform-swt-dev@xxxxxxxxxxx
Subject: RE: [platform-swt-dev] Subclassing Widgets..

Samir.

>I read the document and understand the consequences of subclassing. But
>the Subclassing is a feature of any object-oriented language and when
>someone creates a subclass he/she is aware of consequences the
>subclassing can have. In my case I wanted to subclass the component to
>add some extra features like my custom table with few predefined menu
>whose functionality is fixed. These things can be achieved from
>composition but that is not the right way to do in case of Java.

If you are aware of the consequences and accept that responsibility, the go
ahead and subclass any widgets that you like. Just be aware that your
subclass might not be portable across platforms and might break in a future
release. Aside from that, most SWT widgets can be subclassed quite easily.

-Eric


_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev


_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top