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.
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
Joined: Jun 24, 2003
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
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
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
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
Joined: Jun 24, 2003
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
Joined: Aug 04, 2003
Hi guys, I take your explanations to heart and will create the additional interface/class. Thank you for your help, Felix