I'm trying to refactor some code that works, but where I think I can learn a lot by setting things up better. The part I am looking at is a panel that has several tabs on it. Exactly, what goes on each tab is related, but not the same in every tab. The basic idea, is that I build the tabs and assign each one an actionListener. When the user changes something on the tab, that tabs actionListener is called, which updates an Observable. There are a couple of other panels that use the information, that are registered as observers and they do their stuff when the Observable tells them to update.
Since my tabs are similar, I am building them like this-
Now, the old code has an actionListener something like this-
Obviously the real code has a lot more logic in it.
The variables tabOneNumber and tabOneChoice currently are private variables of the class. I could continue that method of doing things by setting them in the tabOneFields method.
But since I am changing things, I would like to make as many improvements as I can. What I am not sure about is-
1. Should the actionListener be doing this much? Or should it just loop over all the fields and send a block of text to the observer and let it figure things out. My concern there is that the more I go from explicit variables like tabOneNumber to Container[1] the harder I think the code will be to read, especially if this is passed between classes, i.e., the observer gets
String[] tabOneData and the methods make reference to tabOneData[0] or tabOneData[1], whereas now I might have a method updateTabOneNumber().
2. Am I making enough changes? The old code just called explicit makeTabOnePanel(), makeTabTwoPanel() methods and since I am having to both change the number of rows in the tabs and add a new tab, I wanted to be more flexible in this round. The observer keeps a data model that is used to compute the output. The methods the GUI calls tells it how to update the data model. It doesn't seem right (to me anyway) to have a class that has a method like createGUIFields() that I would pass to the observer which would use other methods to extract data. I would like to keep it clear what is used and when. Just not sure how.
Suggestions on how to think about this are most welcome.