Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

B&S:Populate the field information into the Record Object

 
Rico ZHANG
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I am using the VALUE OBJECT pattern which is mentioned in Andrew's book, but I am stuck with a question.

In the instruction of the assignment, in the header information part, it includes the DB schema as well, and all of the field names and length can be found here.
After I read every Record information, I need to populate all the field values into the OBJECT,in my Case, my Record Object is called Contract.And I will populate the information like this(similar to Andrew's book's example)
I will use the Length which grabbed from the header information part.
String name=fieldReader.readField(****,****);
String location=fieldReader.readField(****,****);
String spec=fieldReader.readField(****,****);
...
...
Then : Contract contract=new Contract(name,location,spec,.....)

But if I do this, I have to assume that I have known all of the field names already;I am just wonderring whether it is ok to do that.
Otherwise I have to put a HashMap into the Record Object, then put all the field names and field values into the HashMap. This way will be more generic, then it can be used in future even the DB structure is changed; But it is not tat convenient anyway; and will be weird for a DB application.

Is there anyone using this the OBJECT VALUE pattern? how do you deal with tat?

Cheers
 
mohamed sulibi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hiz;

yes you are right, i use it and in the real live the develop know in advance the fields of the database table. so any change will effect the user of the DAO class as will. you must document your thought about this carefully.

in my implementation i read the schema information dynamic but because there are no way to pass this to the client (i.e DB database = new Data() i through it away it is same as closing the database file issue.

what you think ?

Regards.
Mohamed darim.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic