I'm trying to finsih up Urlybird and was wondering what others have done or are doing regarding the server console and client configuration dialog. I was considering having one configuration dialog class that, depending on the run mode, assembles a configuration GUI for a stand-alone client (select local db file), network client (enter server host and port) or the server console (select local db file and enter port).
At first I thought this was a good idea as it would save on duplicated code (in two of these scenarios the user must be able to select a database file and in two they must be able to enter a port number) so I started coding JPanels that could be reused.
However, after getting it working I'm thinking, while it does eliminate duplicated code, it seems to present unecessary complexity because I end up with a number of switch statements which execute different logic based on the run mode.
If the config dialog code was separated into classes based on the run mode, I think the code is a little easier to follow for a junior programmer but some duplication is likely to happen.
I feel this may be the better option and just justify it in choices.txt.
The book by Andrew Monkhouse has a solution to this problem. I think his solution shares the same code between the server console and client config dialog. You can get the source code from here.. Hope this helps.
I also have a seperate panel which is shared between the client config dialog and the server dialog. Of course you have some switch (or if) statements, because you need to add the correct number of input fields. But in my opinion avoiding code duplication is always a good thing and if you need a few switch statements it's a very little price you have to pay for it
Roel De Nijs wrote:But in my opinion avoiding code duplication is always a good thing and if you need a few switch statements it's a very little price you have to pay for it
My sentiment as well.
I just wanted to make sure I wasn't risking loss of points because I had GUI config code shared/mixed between the server config UI and the stand alone client config UI. Will be sure to justify.