best way of exporting classes/class design
i have some classes that i need to export into text files for transmission
between some legacy systems that i was hoping to get some advice on.
the way it works at the moment is a list of changes made to tables is
kept in
another table in a database. the table they're stored in just contains
the name
of table where the change was made and the primary key. there are a set of
classes that map directly to tables in the database e.g. PRODUCT =>
Product,
COMPANY => Company. periodically a class called UpdateFile is
instantiated which
iterates through the list of changes in the database, instantiates the
class for
which the change was made and inserts the string returned from the classes
updateRecord() function into an ofstream which is eventually written to
disk.
in the past there has only been 1 export file format but now another
needs to be
added in xml. i have been tasked with this and rather than adding to the
confusion i would to improve the design if i can, which is where the
problem lies.
first of all, does it make sense to move updateRecord() and any other
functions
used to generate an export record into it's own class (e.g.
ProductUpdateRecord,
CompanyUpdateRecord) even if it means that class only has the 1 function?
is there any way of templatizing it so that in UpdateFile i can do
for (each change made) {
UpdateRecord<Product> whatever;
ofstream << whatever.text(); //or whatever.xmltext()
}
without leaving updateRecord() in the class its generating the export
record for
(in which case there wouldn't be any use for templates anyway)?
TIA
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]