File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Field Names to the GUI Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Field Names to the GUI Client" Watch "Field Names to the GUI Client" New topic
Author

Field Names to the GUI Client

Dushy Inguva
Ranch Hand

Joined: Jun 24, 2003
Posts: 264
Hi all,
My DBMain interface does not have a getSchema() or a getFieldNames() method. Since this is pretty much the only interface through which the GUI looks @ the database, how do i get the field names across?
1. I can add the method to the DBMain interface
2. I can provide an additional interface holding the method
3. Hardcode the field names in the GUI
oh God !!! Why do i ALWAYS have to choose between one of three choices (It already happened to me twice !!!)
I am leaning towards the second model. Any suggestions ?
Dushy
p.s: I love three tier model. But had to settle for two tier model for this assignment.


SJCP, SCBCD, SJCD, SCDJWS, SCEA (Part I)
Arun Kumar
Ranch Hand

Joined: Aug 29, 2003
Posts: 67
Are you using RMI or Socket solution. If RMI, how did you manage to use the DBMain interface as your remote interface?


SCJP (1.4), SCWCD, SCJD
Dushy Inguva
Ranch Hand

Joined: Jun 24, 2003
Posts: 264
Hi Arun,
Sorry for the ambiguous description. I am using the two tier - RMI approach. I am using an Adapter interface over the DBMain for RMI. (Actually i have not coded it yet !!!)
But since the client should not know the difference between the remote and local database, presently, i am restricting all communication between the database and GUI to happen only through the methods of DBMain (Hope i am making sense!!!).
Right now, i am thinking of providing another interface for the DB which will expose the meta data.
Dushy
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11460
    
  94

Hi Dushy,
I like your second option.
Alternatively, you can add the method to the Data class without putting it in the supplied interface. You would still need to add it to your remote interface though.
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
public interface SchemaIndependantDBMain extends DBMain
{
}


Tony Morris
Java Q&A (FAQ, Trivia)
Tony Morris
Ranch Hand

Joined: Sep 24, 2003
Posts: 1608
public interface SchemaIndependantDBMain extends DBMain
{
public String[] getSchema();
}
Dushy Inguva
Ranch Hand

Joined: Jun 24, 2003
Posts: 264
Thanks a lot Andrew and Tony...
That was helpful.
Dushy
felix kerner
Greenhorn

Joined: Aug 04, 2003
Posts: 17
Hi Dushy,
I implemented a rule in the read method of the data class
that it will return the database schema when I read the
record number 0. Normal reading starts with record number 1.
I don't know If this violates the philosophy of java in
any way. I just coded it that way. (Of course, thats not
how I will justify it in the essay exam, If I have to :-)
Any comments?
Cheers,
Felix
Bharat Ruparel
Ranch Hand

Joined: Jul 30, 2003
Posts: 493
Hello Felix,
You wrote:

I implemented a rule in the read method of the data class
that it will return the database schema when I read the
record number 0. Normal reading starts with record number 1.

In the strictest technical terms, you do not have a problem. However, I do believe that you are introducing unnecessary complexity by doing what you describe above. I would advise you to separate the reading of meta-data in a separate method which could still be a public method of the Data class and return the desired file-header information, e.g., field-names for example. You may want to ask that such a method doesn't exist in the DBMain (or DBAcess) interface. You are right, but Sun doesn't restrict you to only implement those methods in the Data class that are defined in the supplied interfaces (DBMain or DBAcess). I have gone ahead and implemented several private methods and a public method called "getHeaderNames" that returns an array of String containing the field-headers.
Now, as Andrew is advising Dushyanth and Tony is demonstrating above, you want to define another interface which extends the DBMain or DBAcess. Your adapter class, let us call it DataAdapter for the sake of discussion, will then implement the extended DBMain or DBAcess interface. Hope this clarifies the matter somewhat. You will again have to extend this concept by introducing Client side and Server side adapters for remote communication assuming you are using RMI, but let us cross the bridge when we get to it.
Regarding counting records from 0 or 1: I was faced with exactly the same dilemma, and I made the decision to count records starting with zero. This "respects" Java's zero based counting for arrays, functions, just about everything else. If I was doing this assignment in VB, I would count starting with one.
Regards.
Bharat


SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Dushy Inguva
Ranch Hand

Joined: Jun 24, 2003
Posts: 264
Hi Felix,
Yes, I do agree with Bharat. It is better not to change the behaviour of a method based on the parameters of the method. I have extended the interface and am adding the new method to it.
Thanks
Dushy
felix kerner
Greenhorn

Joined: Aug 04, 2003
Posts: 17
Hi guys,
I take your explanations to heart and will
create the additional interface/class.
Thank you for your help,
Felix
 
jQuery in Action, 2nd edition
 
subject: Field Names to the GUI Client