GWT and smartGWT Best Practices

At this point, we've added support for multiple host pages and other languages to myCRM. Now, we're ready to look at some best practices for architecting GWT and smartGWT applications.

In this post, we'll:

  1. Define what we mean by the term Design Pattern
  2. Examine some common Design Patterns
  3. Look at how we can improve the design of myCRM

1. What is a Design Pattern

A Design Pattern can be thought of as a general technique used to solve a class of related problems. Design patterns are commonly divided into the following categories: Creational, Structural and Behavioural.

The Creational patterns all concern themselves with object creation. For example, Abstract Factory provides a way to create and manipulate objects without knowing exactly what they are. The Structural patterns are all static-model patterns, concerned with the structural organisation of your program. Composite, for example, describes a way to organise a hierarchy of objects that implement a common interface. The Behavioural patterns are all dynamic-model patterns, that address the way various objects interact at runtime. For example, Observer provides a way for other objects to be notified of changes to an object's state. The objects don't need to know anything about each other except that they implement certain "listener" interfaces.

2. Common Design Patterns

In 2009 at the Google I/O Developer Conference, Ray Ryan gave a presentation titled: Google Web Toolkit Architecture: Best Practices For Architecting Your GWT App. The presentation discussed the best practices being adopted by several Google projects during large scale application development.

For example:

  • Embrace asynchrony (use the Command pattern for caching, batching and error handing)
  • Use an Event Bus (to deal with complexity)
  • Use the Model-View-Presenter pattern (to facilitate a seperation of concerns)
  • Use Dependency Injection (for application-wide services)

The presentation generated a lot of interest in the GWT community and resulted in the development of several frameworks to help developers adopt these best practices.

For example:

For a step by step introduction to gwt-presenter and gwt-dispatch make sure you check out Andreas Borglin's blog. For a comparison of mvp4g and gwt-platform by Pierre-Laurent Coirier with commentary by Philippe Beaudoin make sure you check out the mvp4g wiki. For a series of posts about MVP, gwt-presenter and gwt-dispatch make sure you check out David Chandler's blog.

Note: Don't forget that you can also learn about these projects by looking at their source code. In Eclipse, you can jump into any method's source code by pressing F3 (which is a shortcut for Navigate -> Open Declaration).

For an update on GWT best practices make sure you check out Ray Ryan's presentation at the 2010 Google I/O Developer Conference titled: Architecting GWT applications for production at Google and Daniel Danilatos presentation titled: GWT testing best practices.

3. Improve the design of myCRM

There are several approaches that we could leverage in order to improve the design of myCRM. We could use mvp4g or gwt-platform or we could try our luck with the MVP and related classes included in GWT 2.1 (currently at Milestone 3).

The mvp4g showcase includes an example that uses Ext GWT. And, this post discusses several possible approaches when using Ext GWT and the MVP design pattern.

Right now, there isn't a lot of information available about the MVP and related classes included in GWT 2.1. However, you could take a look at the Developer's Guide in the GWT Trunk. There is a short comparision of gwt-platform and GWT MVP in the gwt-platform wiki. There is also some information about Places and Activities in Thomas Broyer's blog.

However, a quick check of smartGWT's project page reveals that "Smart GWT is compatible with GWT 1.5.3, GWT 1.6.4, GWT 1.7.x and GWT 2.0.x.". So, it looks like our choice is between mvp4g and gwt-platform (which started out as a fork of gwt-presenter and gwt-dispatch) and based on the number of committers, I've decided to take a look at gwt-platform.

What's Next

At this point, we've decided on our approach to improving the design of myCRM. Now we're ready to take a closer look at gwt-platform.

Getting started with gwt-platform

Comments

Can we use MVP with SmartGWT 2.4

Newly released SmartGWT 2.4 claims compatibility with GWT 2.1.1 does it mean we can use MVP with SmartGWT 2.4, Activities and Places with SmartGWT?

Yes, you can

Hi,

Yes, you can use GWT's MVP implemention with smartGWT version 2.4.

However, Serendipity uses gwt-platform's MVP implementation and not GWT's MVP implemention.

See -> http://code.google.com/p/gwt-platform/wiki/ComparisonWithGwtMVP

Cheers
Rob