On 2010-12-29 01:32:17 -0500, Andrei Alexandrescu
<seewebsiteforem...@erdani.org> said:
I may be misunderstanding, but to me it seems that this design brings
more problems than it solves.
It seems we're approaching the problem from different angles. What you
seem to want is a general way to serialize objects and data structures.
For this task, your concept of Formatter is fine, except perhaps the
virtual dispatch overhead might be unacceptable in some cases.
What I want is a way to serialize specific objects to specific formats.
I don't need all of my objects to be serializable to a RSS feed, but
for those who do I want them to output things correctly, and nothing's
better for that than a formatter class that just takes some values as
function arguments and transform them to a RSS feed, encapsulating the
format within the formatter. This RSS formatter could in turn use an
XML formatter to write the XML output, which in turn could use some
kind a text formatter to convert the text to the desired encoding
before sending it to the transport layer.
So our formatters have different purposes, but they can share the same pattern.
--
Michel Fortin
michel.for...@michelf.com
http://michelf.com/