Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Suggestions on pattern to dump a data structure to a file

16 views
Skip to first unread message

Rui Maciel

unread,
Apr 27, 2012, 2:03:18 PM4/27/12
to
If we have a data structure which we will need to output to a file and we
don't know in advance which or how many file formats we will need to
support, what's the best design pattern to implement the routines to dump
the data to a file?


Thanks in advance,
Rui Maciel

Dmitry A. Kazakov

unread,
Apr 27, 2012, 3:07:25 PM4/27/12
to
On Fri, 27 Apr 2012 19:03:18 +0100, Rui Maciel wrote:

> If we have a data structure which we will need to output to a file and we
> don't know in advance which or how many file formats we will need to
> support, what's the best design pattern to implement the routines to dump
> the data to a file?

This is a classic full multiple dispatch case: Write/Read defined on two
independent type hierarchies: Medium and Persistent. A similar case is Draw
over Surface and Shape. Visitor pattern is usually suggested as a poor
man's solution when the language offers no multiple dispatch.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
0 new messages