Re: Pattern for data conversion between versions



Ted Carter wrote:
Hi all -

Could someone point me to relevant patterns for converting data as it
evolves?  For example, converting data back and forth between different
versions of a database schema.

Regards, Ted.



I suppose that this would be a suitable use of inheritance

class TimetableV1
class TimetableV2 : public TimetableV1
class TimetableV21 : public TimetableV2
etc

The point is to maintain backwards compatibility. Any function that requires a V2 or later timetable can use V2, V21, or any derivative.

To convert V1 to V2:

TimetableV2 tt;
tt.TimetableV1::load(file1);
tt.TimetableV2::save(file2);

To convert V2 to V1:

TimetableV2 tt;
tt.TimetableV2::load(file1);
tt.TimetableV1::save(file2);

I've seen this "pattern" quite a lot in COM interface versioning, whereby extra functionality is appended via interface inheritance, rather than by changing the interface (which is a strict no-no in COM).

Calum
.