I was reading the book “GWT in action 2”, and the author mentioned (in the section where the developer can create a custom widget by extending another one) a hint on how to stop/suppress some functionality of the super class, i.e. methods given by the implemented interfaces.
The way that the author provided was to override the method and add an exception to the GWT log for the developer. Example:
public HandlerRegistration addClickHandler(ClickHandler handler){
GWT.log("", new Exception("Cannot add ClickHandler to ReportSizeLabel"));
return null;
}
Why would I do that, is this a good design?
Why not just return a null, if you must do such a ting?
Maybe I’m thinking too much, anyways, thank you.
I think this is basically bad. Returning null is not helpful for the programmer (it would be better to throw an exception), and the whole thing breaks the idea of polymorphism.
So, the RIGHT answer would be to make an alternative chain of interfaces, to get all of the functions you need but not include
HasClickHandlers. However, practically, that can take a lot of time. If this function threw an exception instead of returning null I’d be willing to put it in internally-used code, but I wouldn’t publish this code to be used by others.PS: the RIGHT answer is probably to correctly implement the method – it’s not that hard in this case.