wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes One more interface with a  getfield method? 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 "One more interface with a  getfield method?" Watch "One more interface with a  getfield method?" New topic
Author

One more interface with a getfield method?

hannes gobel
Greenhorn

Joined: May 04, 2005
Posts: 2
Hello!

Just started on the assignment urlybird where I have got all the header fieldnames and their length from sun. But is it really meant that I shall use these names and hardcode them into my Jtable? I mean I alreade have a method that read them out from the db file so wouldnt it be better to return the fieldname to the gui. BUT....there is no method in the db interface that return the fieldnames. So for now I can see two possible solutions:

1 - Hardcode the values (maybe use a propertyfile for this) into the the jtable in the gui.

2 - let the data.java implement two interfaces. But this is maybe not ok for this assignment, you now the automatic failure?

Can anyone help me with this?

br
Hannes
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
I ran into similar issues where I wanted additional functionality in my data class. I believe both solutions are acceptable. Personally, I am in favor of implementing multiple interfaces, or implementing the provided interface indirectly.

I actually implemented mine indirectly... that is I had the provided DBAccess interface, and I created another inteface, called DBAccessExtender, which extended DBAccess. My Data.java class implemented DBAccessExtender. I recieved full points in my Data section, so this is obviously acceptable. Just make sure to mention it in your choices.txt!


“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Frans Janssen
Ranch Hand

Joined: Dec 29, 2004
Posts: 357
1 - Hardcode the values (maybe use a propertyfile for this) into the the jtable in the gui.

2 - let the data.java implement two interfaces. But this is maybe not ok for this assignment, you now the automatic failure?

Hi Hannes,

I did #1. The GUI is the part that must be concerned with presentation, not the data tier. The names in the data file are (database) field names. Coincidentally, these are quite well readable. But imagine that the database developer had named fields like "RmNmbr" for room number, would you still consider using these in your JTable?

Frans.

P.S. AFAIK you won't be failed for implementing two interfaces, as long as you can convince the assessor that it is a well-thought design choice. At least there is no "must" that forbids implementing multiple interfaces.


SCJP 1.4, SCJD
hannes gobel
Greenhorn

Joined: May 04, 2005
Posts: 2
Thank you very much!

br
Hannes
Liang Anmian
Ranch Hand

Joined: Jun 25, 2004
Posts: 119
Talking about hardcodings, what I've done is that I wrote a subinterface of DB, and one of the new methods is String[] getSchema(), which returns the field names.

However, I have not really decided what to do about the client side. I believe that in one way or another, I need to hard code something. Imagine the scenario where you have to search the database. For my B&S assignment, I have to search by location and name. So now, how do I form the String[] that constitutes the criteria? In order to do that, I must assume that 2 of the fields will be named as "name" and "location" respectively, because I do NOT assume that their positions will always be the same. What if, say, this db admin shifted the name field to another position (e.g now it becomes the second field instead of the first)?

What I intend now is get the schema from the server. Then, when performing the search or book, I search the JTable for the index of the respective fields. From there, I form the String[].

I wonder if this method can be justified?


Current Status:<br /> <br />SCJP 1.4<br />SCJD (in progress)
David Sham
Ranch Hand

Joined: Apr 19, 2005
Posts: 61
If you look at the spec assigment for this project (I also have B&S assignment), you'll notice that Sun put a lot of effort into describing the format of the database file. They really did give all the info necessary to construct the JTable without needing to hardcode anything. I did not hardcode anything (column names or otherwise) for my JTable. I get it all from the db file as I read the schema data in.

However, I do not worry about to many "what if" scenarios either. The schema for the database is so detailed that I do not think the examiner will be changing database column positions in the file to see what would happen in our projects. That would be out of scope.

You can do the necessary calculations based on the field lengths, number of columns, and all the other schema data they provide.

I also extend a sub-interface to the DBAccess interface, and wrote a method to provide the schema data from the db file.
Zee Ho
Ranch Hand

Joined: Jul 20, 2004
Posts: 128
I agree with David, no need to hardcode anything. If you have a method like read(int recno), why not use it to retrieve the header names, maybe you can design a constants like

public static final int RECNO_HEADER = -1;

and do a special handling for such record number in your read method


SCJP 1.4<br />SCWCD 1.3<br />SCJD<br />SCBCD<br />IBM Xml Cert in progress
Lara McCarver
Ranch Hand

Joined: Dec 09, 2003
Posts: 118
If you look at the spec assigment for this project (I also have B&S assignment), you'll notice that Sun put a lot of effort into describing the format of the database file. They really did give all the info necessary to construct the JTable without needing to hardcode anything. I did not hardcode anything (column names or otherwise) for my JTable. I get it all from the db file as I read the schema data in.


They did put a lot of effort into the database schema, and I'm sure that for the exam you could just use their schema to design your JTable, but if this was a real program, that wouldn't be a good idea. Here's why:

1. A database column name is usually not the best name to use in a visible table. In my project (B&S), I think the column with contractor name is just called "name". Suppose that users are confused by this, and you decide to use "Contractor" instead as a column header instead? Or what if in a future version of the database, they add a column to the table but they do the typical programmer name smushing, e.g. instead of "Last name" they use "lastName"... people don't want to see this. This one, you can actually work around without hard coding. If you use a resource bundle (or a property file, but the exam sort of says that one can't be required, I would have to reread the instructions), then you can look up the database name in the resource bundle to come up with the column name. So it's still hard-coded, but not in your normal Java code.

2. There could be columns in the table which are not really suited for display in the user interface. For example, if record id was added to the database in the future, you probably wouldn't want to show it. Or if you had "Last Name" and "First Name", you might want to combine this into a single Name column.

3. The self-describing schema does not include information about which columns are text and which are numbers, and one of the fields in B&S actually represents a list. This is a problem if you want to be able to sort the table correctly. Numbers need to be stored as numbers within the JTable, becasue if you treat them as text, "12" will be put after "1" and before "2".
Liang Anmian
Ranch Hand

Joined: Jun 25, 2004
Posts: 119
Sorry, but I'm still very confused over this issue. Let's imagine I get the schema from the server. Now, when you search, how do you form the String[] criteria? I'm sure it's either:

1) You hard code the column name, and search for the index of that column. From there you form the String[].

2) You hard code the index itself.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

You deside the design of your search method.

You could have your search criteria like this: "[column_id]='[some value]', [column_id]='[some value]'" and on the server you translate the keys into real column keys - or you can use the keys as they are.

The header infomations in the GUI could be hardcoded, because you don't need them for searching.

e.g.
1='Bed & Breakfast & Business', 6='2005/03/10' would on the serverside be name='Bed & Breakfast & Business', date='2005/03/10'

Rene


Regards, Rene Larsen
Dropbox Invite
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: One more interface with a getfield method?