3

Let's make brainstorm about "What could we do to reduce code size in GWT, GXT, SmartGWt etc.?"

For Example; To use a button;

Button b = new Button();
b.setText("Ok");
b.setListener(this);
b.setEnabled(false);

Button b2 = new Button();
b2.setText("Ok2");
b2.setListener(this);
b2.setEnabled(false);

But we could a pattern like factory to create button.

public static createButton(String name, Listener listener, boolean enable){
    Button b = new Button();
    b.setText("Ok");
    b.setListener(this);
    b.setEnabled(false);
}

Button b = createButton("ok",this, false);
Button b2 = createButton("ok2",this, false);

For more buttons I think code size really shows difference, What do you think about this example? Or have you any idea like this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Yusuf K.
  • 4,195
  • 1
  • 33
  • 69

2 Answers2

2

I think creating your button class is another solution

public class MyButton extends Button {
     private String text;
     private Listener l;
     private boolean enabled;
     ...
     ...
     ...

     public MyButton (String text, Listener l, boolean enable) {
           this.text = text;
           ....
     }
}

You can also create with Builder Pattern http://en.wikipedia.org/wiki/Builder_pattern like that

        new MyButton().setText("asd").setListener(l).setEnabled(false).senLength(343)..
 ..constructMyButton();
  • 1
    Yes, I have put the createButton method in MyButton class and define private class constructor. Producing own widget with extending widgets provides convenience. Overriding method when necessary, So changes effects applied all over the developed application – Yusuf K. Dec 17 '10 at 11:39
  • I expect anything. Only want to know about other's solutions. I read your solution and writes my own usage. What do you expect from your answer? – Yusuf K. Dec 17 '10 at 11:59
  • I don't want to be harsh. If I was, excuse me –  Dec 17 '10 at 17:18
  • In addition, in builder pattern all methods must be overriden and must return the MyButton object. So I think builder pattern increase the size of code length instead of factory, do you think? – Yusuf K. Dec 18 '10 at 02:00
1

If your are developing aplications with GXT, and your application's language is different from English. You can define locale from application but in that case compiler generates one English JS and one your locale JS. To avoid this and reduce the compile time. You can replace your locales messages content from com\extjs\gxt\ui\client\messages\XMessages.properties instead of using com\extjs\gxt\ui\client\messages\XMessages_it.properties