Let the interfaces separate from the classes first.
Interfaces are great for bullying (which allows you to test your application without the need for a sluggish GWTTestCase ):
IsWidget : when all you need is a widget handle that is independent of the Widget class. This is usually used with MVP as a way of presenting a view.AcceptsOneWidget : when you need a placeholder for one widget (in the form of IsWidget ). This is typically used for operations to insert a view ( IsWidget ) into a given slot ( AcceptsOneWidget ).
All the classes you listed are extended by Widget , so they rely on JSNI and (most of the time) should run in the GWT environment (for unit tests, which means GWTTestCase ):
Widget : the base of all widgets. Implements IsWidget returning from asWidget() .Composite : the base class when you need to create a widget created from other widgets, hiding their implementation. Although you can extend an existing widget, it's best to hide it inside the Composite so that you only expose the API that you need / should show. Composite is "composition, not inheritance" and encapsulation. Examples of composites in standard widgets include TabPanel (built from TabBar and DeckPanel ), DateBox (built from TextBox and DatePicker in PopupPanel ), ValueListBox , which wraps ListBox or ValuePicker , which wraps CellList . In many cases, given that panels accept IsWidget , you can simply implement IsWidget to expand Composite , but it is sometimes useful to have a true Widget .SimplePanel panel that implements AcceptsOneWidget , useful as a slot when using actions (but you can also easily implement AcceptsOneWidget to insert into any panel)
Talking about this, Google recently published a GWT-Mockito that connects Mockito to GWT.create() and uses the classloader manual to overwrite JSNI methods and remove final modifiers so you can directly use widgets in tests without the need for GWTTestCase or MVP.
So, overall, it depends on how you approach your code, how you use the architecture of your application. If you use MVP, stick with the interfaces ( IsWidget , AcceptsOneWidget ) in your presenter so that you can easily make fun of your opinions in your tests.
Otherwise, or if you want a “simplified MVP” where the view is a UiBinder template, try GWT-Mockito for your tests and use widgets directly.
Of course, you can mix both approaches in one application. And in any case, create your own widgets as a Widget for low-level things (rarely required) and Composite or IsWidget for everything else, and not to extend existing widgets.
Thomas Broyer
source share