Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Business Logic and Hardcoding column name to locate a column index?

 
Karl Fu
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program works ok but recently I have been thinking of refining the design patterns and the placement of the business logics.
In the booking method, we have to know the column index to find out which column is the Flight no, Origin, Destination, available tickets, etc...
How do we locate that column index in the table ?
eg. on the server side
int findFieldIndex(String columnToLookFor){
FieldInfo[] fieldInfo = getFieldInfo();
int i = 0;
while (i < fieldInfo.length) {
if (fieldInfo[i].getName().equals(columnToLookFor))
return i;
i++;
}
return -1;
}
In the booking method (on serverside), say i need to find available seats....so i call findFieldInfo("Avaialable Seats")
Do you think it there is a way to do it without hardcoding "Available Seats") on either the client or server side.
if not, is it better this method to put it on the server side ?
I have been think putting this on the server side because if the database schema changes, it will not affect the client program. Modification is needed only on the server side.
As well for the booking method, if i placed it on the server side, it appeals that it becomes more atomic and resistance to client disconnections.
However, I need to add an method in the remote interface and the remoteImpl in order to do that. Should such helper method be placed in there or should I simply it in the GUI as a helper method (but i don't think it is a good idea), or other places ?
In short, I added 2 helper methods, "booking" and "findFieldIndex" on the server side, Any comments ?
 
Aleksey Matiychenko
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my data class constructor I added a call to createFieldIndex method which populates a hashtable with names of the columns as keys and their index as values
 
Karl Fu
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aleksey,
Yes, i see your point of adding an hashtable for the indexing services. Definitely speed up the process and i like it. I have one question though , when we retrieve the information from the hashtable, say Available seats, we have to do :
int index = hashtable.get("Available seats")
Do you consider this is hardcoding the table column name in our program ? You said you have the hashtable in your data class? Did you add any methods in the data class to access the hashtable ? did you return this index to the client ? If yes, you have to add another method in the interfaces right ? If not, does that mean that you put the entire booking business logic on the server side?

Thanks in advance
Karl
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aleksey!!
answer us
Do you consider this as hardcoding?
/Daniela
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you have a coding taking this long, I guess it doesn't matter whether it is hardcoding or not.
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don,
What do you mean? You don't think it is a good idea?
/Daniela
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Daniela Ch:
Don,
What do you mean? You don't think it is a good idea?
/Daniela


I was just joking, because I saw the last message was left on May, 2001.
 
Daniela Ch
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aahhh!!
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic