Over a million developers have joined DZone.

The Ease of Angular with GWT

· Java Zone

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

Let's see a quick example. Our framework builds with the standard GWT MVP, but we eliminated view and presenter interfaces. We are also relying on pure html templates, not gwt ui.xml-s or imperative UI building, but that's your choice.

Now let's say we have HTML template:

<span id="nameLabel"/>
<button id="myButton">Clickme</button>

And in the ViewImpl class:

new LightLabel("#nameLabel")
    .bind(bindOnPresenter().get(Presenter._labelText));
new LightButton("#myButton")
    .bind(presenterMethod(Presenter.__buttonClicked));

And the Presenter (that's also the Activity):

@ObservableAttribute
private String labelText;
[...]
@MethodRef
public void buttonClicked() {
    setLabelText("You clicked me!");
}

Note a few things:

  • The example framework uses html templates, but you're actually free to use your own solution in ViewImpl classes
  • The ViewImpl class is dumb: it merely declares components and their bindings.
  • The bindings are easy to express with the magically generated property and method literals , but it's still typesafe, compile-time checked.
  • In this example the presenter is also the model (it contains the labelText), but that's also your choice, you can put it in a different Model class.
  • The presenter works with the model only. Changes are automatically propagated to the view and vice-versa. There's no need of a view or presenter interface, and you don't have to manually propagate data to the view components and manually fetch them when you need them in the presenter. They're just there.
The magic I mentioned is performed by lombok-ds, our extension of lombok-pg. We are planning to switch to APT though.
Well, the above example is probably the most simple one. The github page contains more examples and principles to follow. We implemented an entire large-scale project with this approach, and it turned out to be pretty cool.
Please let us know if you're interested.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}