Apikoulas wrote:Could someone highlight the pros and cons of declaring widget variables:
a) locally on the method (as final to allow reference in anonymous class listerner)eg
- Code: Select all
public void onModuleLoad() {
final Button button = new Button();
.....
}
b) declaring as class member variables (which to me looks more clear)
- Code: Select all
public class ImageViewer implements EntryPoint {
private Button button = new Button();
}
I have also come across some extremes, such as declaring vars in a method
inside a block eg. { Button b = new Button()...} -
Is there any point in that ?I feel that b) has these pros :
- More clear code, seperation of declarations & code
- Vars can be referenced by other methods
Hello,
this could be answered in many ways, especially if you also want to take JVM/Javac optimization into scope. There are sometimes rules within organization that put some design/implementation details rules to follow, sometimes one is free about implementation details and can follow own habits, etc.,
Here is a nice book you could read on that subject:
http://safari.informit.com/9780321413093it covers most of answers you would probably receive from coders
In GWT (toolkit) terms: you're free of choice on implementation details, Even "final" has no real importance in GWT. That's because GWT (toolkit - i'm not writing about GWT Desinger plugin+Eclipse) does not use Javac - at least on code that is to run on client side. Everything is compiled by GWT compiler (transcoded from java to javascript, optimized, etc),
regards,
Peter