Posts Tagged ‘GWT-Ext’
The GWT-Ext Best Practices
It’s been a while since I’ve written anything. For the past four months I have joined a new company and we have been busy designing a new web service for an Australian client.
Having been jumping around initially, from .NET, to later Java Struts, then HTML+CSS+JS, I have finally landed on the land of GWT. What is GWT?
Together with GWT-Ext, GWT can help you make your next Internet application rich without you ever touching JavaScript. And that’s great news, since type-checking and debugging is way easier in Java than in JavaScript. (Still, it wouldn’t hurt if someone can make a WYSIWYG designer application for it… but I think for now we have to get our Java hands dirty – not that I don’t like it that way
.
Here are some of the things I recommend that everyone using GWT-Ext doing. These are my personal preferences and, while can be made “best practice”, are certainly my opinion alone.
Extend the GWT-Ext Panel class
Why? Well, it makes me think more clearly. I can now say that all objects within my UI package are panels! Just add the panel objects together for a complete GUI!
Put all constructing commands in constructor and extract methods often
For complex panels, the main constructing function (the constructor, assuming you extend your Panel class) will expand to 200 or so lines easily. If you use Eclipse, use its extract method refactoring facility often. This way you can organize code by its function, and it will be more manageable.
Keep your enumerations in String
Don’t use Java enums. You’ll have to use a static class to forward any information from one Panel to another anyway (the information is most likely in a form of String object!), so Java enums will only add more maintenance load later. Yes, you’ll have to live with a lot of if-and-then’s for your factory classes, but I think that’s a good trade-off compared to forcing to use constants and enums.
Document as you code
I can’t stress that enough, and it’s just as applicable in Java as it is on any other platform. Eclipse and NetBeans have made it very easy for you; you just need to type in your explanation above the function you just declared (denoted within the /** { JavaDoc tag } */)! Both Eclipse and NetBeans can parse these information snippets and trust me, when you come across your own buggy code two months later, you’ll need it. Take time writing it; it will save you a lot of time and confusion down the road. Don’t be lazy!