Google Web Toolkit Applications : what's the best design pattern?
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hello,
I recently started out using GWT for the (obvious) reason that, while I regard myself as a Java 'expert', I know (and wish to know :-) very little about Javascript.
Shortly after starting out, I fell back on to the MVC pattern, using the 'main' (entry point) class as the Controller, creating a bunch of View(s) - using the well-trodden View interface and AbstractView - as well as a bunch of command (and could I fail in implementing an AbstractCommand and SimpleCommand?)
So, it all looked gorgeous and very OO-like...
but it left me wondering: is this the best way of doing things in GWT? was I re-inventing the wheel?
And, on a related note: it is my understanding that one does all the styling and UI-related stuff in the CSS(s) - although GWT gives you more than a few backdoors to do that directly in Java. Is this really the accepted gospel, or is there a middle ground? a better way?
Will be looking forward to reading your views and the book!
Cheers,
Marco.
I recently started out using GWT for the (obvious) reason that, while I regard myself as a Java 'expert', I know (and wish to know :-) very little about Javascript.
Shortly after starting out, I fell back on to the MVC pattern, using the 'main' (entry point) class as the Controller, creating a bunch of View(s) - using the well-trodden View interface and AbstractView - as well as a bunch of command (and could I fail in implementing an AbstractCommand and SimpleCommand?)
So, it all looked gorgeous and very OO-like...
but it left me wondering: is this the best way of doing things in GWT? was I re-inventing the wheel?
And, on a related note: it is my understanding that one does all the styling and UI-related stuff in the CSS(s) - although GWT gives you more than a few backdoors to do that directly in Java. Is this really the accepted gospel, or is there a middle ground? a better way?
Will be looking forward to reading your views and the book!
Cheers,
Marco.
Marco
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
GWT is very intuitive to a Java developer and I think your on the right track using Model-View-Controller. Of course you don't have to use MVC, but it is a well understood way to organize a client facing application. The big benefit with MVC is the decoupling of the major parts of your application. Being able to use the model or controller separately for performance or unit testing or even switching views are big pluses. Also, if you're working on a team using common patterns like this your colleagues are going to understand what your doing a lot quicker.
In my book each of the five example applications, chapter 6-10, are based on MVC design. The controller is typically loaded from GWT's EntryPoint.onModuleLoad method. It does the job of loading the model from a server, and populating/listening to the application
s view. The model objects are usually just POJOs which can be used directly over GWT RPC to a Java Servlet. You can also build your model from GWT's XML or JSON DOM. For the view, GWT has a user interface framework similar to Java's AWT with widgets and an event model. There are basic widgets like buttons, complex widgets like a tree, and layout widgets called Panels. You can construct your own widgets from scratch or by combining other widgets using GWT's Composite.
As for styling your interface, CSS is the way to go. CSS is fairly standard between browsers (see http://www.gwtapps.com/?p=22 for an important exception). It's declarative and easy to learn. It's also important to separate user interface styles from your application code since you may need to have a less technical professional make your app look great.
Recently, however, I've been digging into the GWT incubator project which has a StyleInjector class allowing you to bundle CSS, including background images, inside the single JavaScript download of your application. This may be the start of more sophisticated handling of CSS where GWT compiles it similar to how it handles JavaScript. Here's a post where a couple of GWT engineers are talking about it: http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/cb9605b64edf0154
[ November 13, 2007: Message edited by: Ryan Dewsbury ]
In my book each of the five example applications, chapter 6-10, are based on MVC design. The controller is typically loaded from GWT's EntryPoint.onModuleLoad method. It does the job of loading the model from a server, and populating/listening to the application
s view. The model objects are usually just POJOs which can be used directly over GWT RPC to a Java Servlet. You can also build your model from GWT's XML or JSON DOM. For the view, GWT has a user interface framework similar to Java's AWT with widgets and an event model. There are basic widgets like buttons, complex widgets like a tree, and layout widgets called Panels. You can construct your own widgets from scratch or by combining other widgets using GWT's Composite.
As for styling your interface, CSS is the way to go. CSS is fairly standard between browsers (see http://www.gwtapps.com/?p=22 for an important exception). It's declarative and easy to learn. It's also important to separate user interface styles from your application code since you may need to have a less technical professional make your app look great.
Recently, however, I've been digging into the GWT incubator project which has a StyleInjector class allowing you to bundle CSS, including background images, inside the single JavaScript download of your application. This may be the start of more sophisticated handling of CSS where GWT compiles it similar to how it handles JavaScript. Here's a post where a couple of GWT engineers are talking about it: http://groups.google.com/group/Google-Web-Toolkit-Contributors/browse_thread/thread/cb9605b64edf0154
[ November 13, 2007: Message edited by: Ryan Dewsbury ]
| if you think brussel sprouts are yummy, you should try any other food. And this tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |









