M
Markus Dehmann
I have an abstract base class called Data. It has a pure virtual
function
virtual void write(std:stream& out) =0;
which writes the internal data to a stream. Now the problem is that
this is not appropriate for some implementations of the class. Some
implementations have an internal representation that they should
rather write into several separate files. So for those, something like
this would be more appropriate:
void write(const std::string& outputDirectoryName);
What would be a good design for the abstract base class in this case?
It seems like it should require some kind of write function, but with
flexible parameter lists for different implementations.
Certainly we don't want to deal with void pointers:
write(void* toWhatever) = 0;
that the implementation classes would cast and use however they like
because void pointers are evil.
A template also doesn't work:
template<class T>
virtual void write(T& out) = 0;
because you can't template a virtual function. And it would seem like
overkill to template the whole class on this output parameter; after
all it's just a little write function within a much larger class.
What would be a good design in this case?
Thanks!
Markus
function
virtual void write(std:stream& out) =0;
which writes the internal data to a stream. Now the problem is that
this is not appropriate for some implementations of the class. Some
implementations have an internal representation that they should
rather write into several separate files. So for those, something like
this would be more appropriate:
void write(const std::string& outputDirectoryName);
What would be a good design for the abstract base class in this case?
It seems like it should require some kind of write function, but with
flexible parameter lists for different implementations.
Certainly we don't want to deal with void pointers:
write(void* toWhatever) = 0;
that the implementation classes would cast and use however they like
because void pointers are evil.
A template also doesn't work:
template<class T>
virtual void write(T& out) = 0;
because you can't template a virtual function. And it would seem like
overkill to template the whole class on this output parameter; after
all it's just a little write function within a much larger class.
What would be a good design in this case?
Thanks!
Markus