-
More Java GUI queries
Well, i've been working flat out with some excellent results but i've been pondering;
What i've done is put each page of my GUI into a seperate class because there's a lot to deal with in each page, one class for the GUI would simply be too little, i was reaching 500 LOC with one page and needed it to be more dynamic and understandable so i put them into different classes. Is this a good idea? Any other methods of approach used that anyone else has experience with?
Cheers
-
There's no hard and fast rule of amount of code per class. I have some classes with 3000 lines of code, and some with 10.
-
It's more for increased readability than anything
-
I would think personally for overall understandability of the project, at the beginning of the class, make some comments, well thought out and descriptive of what this particular class is trying to achieve and where it is used. Something like that. And well written comments on top of the methods would help as well. Generally i prefer not to write too many comments because it gets messy quick. But I dont think there is a hard and fast rule as to when to break things down into separate classes. For my little XML IDE for example I started about with having one fat gui class but then I realized breaking it down would make it more manageable and while it worked for a readability and logical point of view, the programming got a slight bit more complicated.
-
That's what i was hoping to hear :) I'm on my way now, shame my deadline is a week and a half early. Due in on monday, bit fudged for that as there's some advanced algorithms i'm meant to write for it which i haven't yet :S
-
It's normally best to ensure each class has a limited well-defined responsibility - makes it easier to test and you know where to start hunting bugs. So a GUI class could just take user input for one window, feed it to the application logic class(es) and display the result. Needs a bit more planning than the all-in-wonder GUI but it should scale better.
-
It's just amazing how such a small project can have such a large GUI code wise. But yes, each page on my GUI has a seperate class, and each class has get methods to i can return each button or text field etc. so i can pass it to the action listener in the main UserInterface class
-
Ahh Kezzer you just solved one of my problems hahaha. Hmm a get method...that is quite interesting...wondering why I didnt think of that. lol
-
Get methods are what allow you to do message passing. They're the source of all OO ;)
-
Yes that is true, but somehow they did not seem that elegant to me previously but now it does actually!