views:

437

answers:

3

Hey,

every time i code a gui (in my case with GWT, never touched gui programming before), i notice that my code becomes a big mess, when the applications becomes more complex.

It's really frustrating to look over my code and get a headache of all these setters in object constructors and this messy throwing together of these.

I am using the MVC Pattern and it really helps to get a lot clearer. Unfortunately my whole view component isn't clear at any point. ;-) I tried to use a lot of interfaces to abstract from the building process and to have just a few implemented interfaces which will be added together, (I thought i could switch between different libraries, like Gwt-Ext and Gxt, easily) but still i am not really happy.

I am sure you had this problems too, and i want to ask you what practice do you follow to get cleaner code? Are there design patterns for gui coding except MVC? What are your tricks for highly readable and beautiful user interface code?

+7  A: 

Martin Fowler wrote interesting article on this topic: GUI Architectures

Peter Štibraný
My favorite summary also.
le dorfier
+2  A: 

When I'm coding a GUI in GWT I like to create Widgets that do just some small task. This way It becomes much clearer when you then combine those widgets in the final view. On the other hand you can get a widget mess all over. So try to balance what can go in a new widget (to be used on many places) and what in the view.

Drejc
A: 

Seems more like a very general programming problem then just GUI related. Why do you feel that this only happens with your GUI code? Is your only problem that your view components feel cluttered by getters/setters and constsructors with many parameters?

Not much you can do about constructors with many parameters except making sure that all parameters are actually needed. You might want to have a look at the Builder pattern btw. It probably wont reduce the number of parameters, but it is good practice to restrict the use of the new keyword.

Probably not the answer you were looking for, but see if you can be more specific about the problem and why you feel it only happens in your GUI code.

willcodejavaforfood