In article <11**********************@g10g2000cwb.googlegroups .com>,
"Guch Wu" <gu****@gmail.com> wrote:
I want to design an image processing class as follow:
class Image
{
Image Data;
General Image Operations;
read(filename, File_Type);
write(filename, File_Type);
};
The Image Data is initialized by the read function according to the
File_Type, and save to a file by write function according to the File
Type.
The problem is:
Whenever adding a file type, I have to add two functions(read and
write) to the class Image.
I want to know if there is a design pattern which bring less
modification to the class Image when adding a file type.
Any suggestion will be appreciated!
I don't think there is any way to do what you want. There are things
that you can do to limit the size of the read and write functions by
reusing like structures within them, but the only way to eliminate
needing them is to make some read only or write only (depending on what
you are writing, this may be a good idea anyway.)
I suggest, however, that you read up on the Strategy pattern.
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment.