• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S numarical fields as Strings

 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

in the B&S assignment we have got some numerical fields such as rate, number of staff etc. I have two alternatives on how to deal with these numerical values:

1. store them as strings, since there are no numerical operations required for the assignment. But when it comes to maintaining the code later on it should be changed to alternative 2.

2. store them as numerical values, and deal with all the extraction related code and currency related issues.

which one do you think is better alternative?
Thanks
Regards, Musab
 
rinke hoekstra
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was doubting about this too. I haven't decided yet. Converting them to numerals has the advantage that on the fly you could do some validation. But, you might as well do validation without the conversion.
 
Mark Ebeling
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have decided to only change the size to integer. I left the rate alone since I have no business knowledge of how it will be used later. Remember KISS.

That's my 2 cents.
 
Musab Al-Rawi
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
makes sense but becaureful, integer in java takes 4 bytes while the size in the DB is 6 bytes... now for the current numbers it won't harm but may be you should consider using long.

what do you thik ?
 
Mark Ebeling
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood, but since the DB is padded with spaces and I am padding with spaces to be consistent, it really doesn't matter here.
 
Gabriel Vargas
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

I attack this problem for two sides, first number format validation and conversion is done for my Contractor class because it stores the values in a proper way but he didn't know the lenght of the fields, second the field length is validated with the values stored when header is readed, so i only have a small method in my data class (database manager) than makes this validation.

I hope it helps.
 
MarioAixel Rodriguez Jaen
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At first I decided to convert all the data types that made sense to numeric. Due to the nature of the data it was easy to convert them. Rate, size, or customer id are definitely numeric. In contrast to a phone number field or a zip code where the convertion could be handled in different ways.

Then I thought in adopting a pattern of a valueList. In this option there are methods of the style, <code>String getAttributeString(String attrName)</code>, <code>getAttributeNumeric(String attrName)</code>, etc. that will convert the value to the desired outcome.

It was just a thought. The cool think about the latest approach is the flexibility. But then again, probably it is better to have a model in which all the data types are "strongly typed", which is what I chose at the end.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic