posted 16 years ago
I'm writing a project to be graded, and one of the important parts of this project is good code structure. Good encapsulation, loose coupling, and all that. However, I have a problem when it comes to my GUI.
My program uses standard UI-model separation, and all the GUI classes are in their own package. I decided to implement my GUI actions by subclassing Swing's AbstractAction, so that I can use the same action in tooblars and menus if I like. My program is not complicated enough for a controller, so the actionPerformed method in each of these AbstractAction subclasses does all the work associated with that action. As of now, these AbstractAction subclasses are inner classes within my main GUI class.
This GUI file is getting outrageously long, and it is the only class in its package. The action classes could stand on their own, but I would have to open up my GUI's private component instance variables to package access. As a result, only classes within the package would be able to use these variables, but they would be opened up nonetheless.
<b>Bottom line: is it better design to keep all these AbstractAction subclasses within my GUI class as one enormous file, or should I make them separate classes and give my instance variables package access?</b>
Thanks everybody!
-Matt
Current CS undergrad
SCJP 5.0