[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.platform.swt] Re: Why is composites like Table not intended to be subclassed?
|
I believe that the reason most SWT widgets have that warning is because most of the classes are pseduo-final. That is, they've been developed without any consideration for subclassing, and thus anyone who does subclass may have to change the subclass for each release (especially the internal ones). However, rather than making it final (which would prevent anyone subclassing, whether they had a legitimate need to or not -- such as yourself), a strongly worded comment indicates that if you do subclass it, it's up to you to fix it when they change the superclass without telling you.
It's mentioned briefly in the API Rules of engagement:
http://help.eclipse.org/help30/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/misc/api-usage-rules.html
There are also some classes which call 'checkSubclass()' and throw an error if this.getClass() doesn't match the expected value. You might have to override this method if you are subclassing Widgets.
http://help.eclipse.org/help31/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/Widget.html
http://help.eclipse.org/help31/nftopic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/swt/widgets/Widget.html#checkSubclass()
"Checks that this class can be subclassed.
The SWT class library is intended to be subclassed only at specific, controlled points (most notably, Composite and Canvas when implementing new widgets). This method enforces this rule unless it is overridden.
IMPORTANT: By providing an implementation of this method that allows a subclass of a class which does not normally allow subclassing to be created, the implementer agrees to be fully responsible for the fact that any such subclass will likely fail between SWT releases and will be strongly platform specific. No support is provided for user-written classes which are implemented in this fashion.
The ability to subclass outside of the allowed SWT classes is intended purely to enable those not on the SWT development team to implement patches in order to get around specific limitations in advance of when those limitations can be addressed by the team. Subclassing should not be attempted without an intimate and detailed understanding of the hierarchy. "
Alex.