This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Hardcode or using getHeaderNames?

 
Jonathan Liu
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using getHeaderNames this kind of method can read the field name from db file as Header Name in JTable. But the detailed descriptions are not stored in db file which can be useful tooltip, so if I want tooltip, I have to hardcode the View code, this is what I am trying to avoid of .
Thinking about MVC,MVC is used to sepearte business logic with presentation and control. View is responsible for presentation and should be made UI friendly, so I think for View, friendly UI carries more weight than dealing with potential field name changes.
Which one do you perfer, my friends?
Please give me some comments.
 
Javini Javono
Ranch Hand
Posts: 286
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm not sure I understood your question entirely, but here goes:
For example:
* given field name in file is "name"
* and detailed description to use in tool tip is
"The name of the hotel this vacancy record relates to"
which is not in the database file.
I don't see any way the string "The name of the hotel this vacancy record relates to"
can get into your program unless you "hard code it" (either literally or
have it available in a file, perhaps a keyed file (see Properties class), i.e
the properties file would have this line:
name=The name of the hotel this vacancy record relates to
If the long definition of "name" is in a properties file, at least it is
more isolated, but it is still, at some point, typed in by a human.
Aside: Assume, and this may or may not be a consideration in your
design: that in the future you may have more than one database file.
Then, call the current database file "DB1" and then in the properties
file you can say:
DB1.name=The name of the hotel this vacancy record relates to
Now, refering to the simpler example above for the properties
file:
name=The name of the hotel this vacancy record relates to
we have, of course, "hard coded" the string "name". What you
can do, is after reading the header information, scan the properties
file to make sure every name, such as "name", is defined, and if not
notify the developer that the database field labels are not consistent
with the properties file.
Note that even though we hard-coded the string "name" in the
properties file, we are doing this because we are writing a
simple translator, and the definition of "name" is
"The name of the hotel this vacancy record relates to"
which has to be defined somewhere.
Thanks,
Javini Javono
P.S.
My program will not hard code the field names, such as "name",
but instead, read them from the database file.
[ January 14, 2004: Message edited by: Javini Javono ]
 
Jonathan Liu
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you,Javini
For simplicity, we can read the header name from the db file, without caring about Tool tip.
I just wonder from the perspective of MVC, shouldn't we make the GUI more friendly ? So does this mean hard code is better?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jonathan,

For simplicity, we can read the header name from the db file, without caring about Tool tip.

In addition, you can provide a mapping inside the properties file.
If there is a mapping, it displays the "nick name" of the header, otherwise, displays the original name.
e.g. inside the properities file, we have:

If we found such mapping, we use Hotel Name inside the JTable heading. If not, we use name.

So does this mean hard code is better?

Why need so? You can put the field names inside the Transfer Object (TO), and when the server send the results back, the JTable can obtain the header from TO easily.
Nick.
 
Jonathan Liu
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you guys all use ToolTip?
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jonathan,

So, you guys all use ToolTip?

I have used ToolTip.
Nick.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic