The aspect of programming I have the least commercial experience is starting to reaaaaaally annoy me. GUI development. I just can't get a clean design!
At first I coded everything into the JFrames. Basically all the logic of validating input, calling the RemoteDatabaseAdapter etc etc was in the frame. This obviously resulted in HUUGE classes that were fairly difficult to comprehend.
I left the assignment for a couple of months, and when I looked at the GUI implementation I decided to recode the whole thing. So I read up on this MVC pattern that everyone is so extatic about and was fairly impressed. It does look like a really neat pattern.
So after looking at a few examples and such I developed a little MVC framework with three interfaces:
However, when I started implementing the GUI as Hierarchical-MVC I immediately ran into problems. I think this mainly stems from all H-MVC and MVC examples incorporating like one JFrame with one textbox and one button rather than realistic examples... OR J2EE Java/Servlet/JSP orientated.
I went H-MVC all the way and made the settings windows, connection window, the search bar, the JTable and the hosting JFrame all into MVC triads...
My first problem was that h-MVC as I seen it documented could only speak top-down, not bottom-up, so I had to add AbstractChildControllers implements Controller that could send events to classes that implemented the ParentController interface. This meant controllers could talk both up and down in the hierarchy, but something at the back of my head was telling me it's a bad idea as it creates two-directional references.
Then I started thinking about the absurdity of having controllers that basically don't do anything other than call a methods with the same signatures as in the view, and was thinking maybe I should have several views but the same controller for most of them as the views are so simple and closely linked. Then I thought, naaah I have to be consistant with the pattern, let's keep all the triads even if the Models for instance are empty.
Then I realised that I wanted ALL components to listen to the DatabaseModel as that sent important events like when the connection is broken, so I had to change the View interface to be able to listen to additional models... MORE complexity.
After coding for several days I took like two steps back from the computer and said �!�*%@!, this doesn't look ANY cleaner or simpler than what it did when I had everything in JFrames. POSSIBLY slightly more reusable at the cost of having generated a complex H-MVC framework with like 10 classes and now having around 15 GUI classes for the triads. 25 GUI classes in total, HELP!
I NEED advice... What did you guys do? How did you keep it clean and simple? Did you only use one model, one controller and several views? Or even just one model, one controller and one view??? What obvious MVC-newbie mistakes am I making?
I'm not so experienced with GUIs, but this is how I did it:
My data model contained the retrieved records. I registered action listeners (subclasses of javax.swing.AbstractAction) with my Search and Book buttons. In these listeners I added the code to access the DB (using a business delegate) and update the model, notify the views and take care of any exceptions.
I felt using the AbstractAction and the business delegate really helped keeping my design clean.
I had 8 GUI classes: 3 action listeners, 1 model, 3 panels (search, book, status bar) and 1 class to put it all together.