This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes server console and client config dialog Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "server console and client config dialog" Watch "server console and client config dialog" New topic
Author

server console and client config dialog

Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
Hi all,

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.

Feeback please. Thanks.
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

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.


SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5449
    
  13

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


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Ed Ward
Ranch Hand

Joined: Jan 30, 2006
Posts: 147
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.

Thanks again!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: server console and client config dialog