Why Composite?

25 views
Skip to first unread message

richip

unread,
Apr 23, 2011, 6:44:58 PM4/23/11
to Google Web Toolkit
Why would I wish to extend Composite instead of just extending the
Widget that I'm wrapping in the Composite?

Harald Schilly

unread,
Apr 23, 2011, 7:10:16 PM4/23/11
to google-we...@googlegroups.com
When you want to design your own widget that modifies some data, you can combine more than one widget in such a Composite, additionally implement for example a HasValueChangeHandlers<...> interface, and much more. That helps to isolate all this into one class and you can use this as a bigger block when designing the UI.

H

Gilles B

unread,
Apr 24, 2011, 10:21:04 AM4/24/11
to Google Web Toolkit
This is true but keep in mind that if you use inheritance to extent a
widget your object must follow the "Is A..." rule.
Il you extent a button with a new child class "MyButton" or
"MyToolbar" you inherit all present and future methods, your object
can be cast and used as a parent representative, it is also a Button
and a Widget as example. So may be "MyToolbar" is not a good idea here
because it is a button set and no a single button (The Rule "Is A
Button" is not respected). The composite is a good way to build a new
widget mays be with various smaller widgets and java code as glue
(another one is wrapping the JS component using native methods).
Inheritance has to keep the original widget idea with only
specialisation like button with image as a sort of button or
IntegerTextBox as a interger input dedicate TextBox. So if (and only
if) the "Is A" rule apply it seems better to inherit.
Hope it help a little bit. G. ;-)
Reply all
Reply to author
Forward
0 new messages