The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Instantiating objects from file

I have a number of different types which differ slightly the object contents for which come out of a text file(s). Is there a design pattern / design pattern combo that I can use for this? I've had soemthing working in the past that was quite aestetically pleaseing, but A) I have forgotten, and B) my brain is not working today.

Monday, January 14, 2008
 
 
Are you talking about serialization?
Dan Fleet Send private email
Monday, January 14, 2008
 
 
Check out the following c++ faq, there are some good general advice, regardless if you use c++ or something else.

http://www.parashift.com/c++-faq-lite/serialization.html
Anon
Monday, January 14, 2008
 
 
What language are you using? In Delphi we just use WriteComponent and ReadComponent to write the component (object) to a file.
Mike Send private email
Monday, January 14, 2008
 
 
I wasn't looking for implementation, simply how best to design it. Assume I am using some made up OO language.

Wednesday, January 16, 2008
 
 
You need to come up with some representation for the all possible datatypes of members of the class, then have methods that can introspect the class, or an interface on the class itself that outputs that representation.  Likewise for reading it in.

Depending on how often the class structure changes you need to worry about versioning of the serialized data.  You also have to consider object graphs (e.g. circular references) and fields that have no need to be serialized.

Many languages have a native serialization protocol, or often people will write their own using XML, JSON or the like.

Really depends on your requirements.
Dan Fleet Send private email
Wednesday, January 16, 2008
 
 
mmap
Mr. Grunt Send private email
Sunday, January 20, 2008
 
 
Ooops sorry it should be a text file. So you can use serialization or simple parsing or even sscanf
Mr. Grunt Send private email
Sunday, January 20, 2008
 
 
Since you mention it has to be a text file, and you use different non object/class data types, I suggest JSON (lightweight alternative to XML). There are other text based alternatives, like CSV files, but hard to read. Cheers.
Marco Aurelio Ramirez Send private email
Saturday, January 26, 2008
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz