I have a requirement to save an image file in various formats. The list of formats is subject to change quite often, so I wish the saving would be very extensible. Also, the saving can take place in many places (hard disk, ftp, http, etc). The list of saving locations is going to change very often too.
I thought I would use a base Image class and many deriving classes for each format:
ImageBase {} JpegImage : ImageBase {} TiffImage : ImageBase{}
and handle saving in each subclass appropriately to format. Is this a good design desicion?
Also, how can I attach an extensible Saving location mechanism (Ftp, file share, etc)?
I would like something like this:
var image=ImageBase.GetImageFromDisk(path); //some casting to subclass maybe?? var tiffImage=image as TiffImage; tiffImage.Location=new FtpLocation();//not sure if this is a good idea tiffImage.Save();
The problem here, is that concrete image implementation should not know or care about the saving location. When calling Save(); on image subclass, I would like to delegate the work to some class, like FtpLocation.
Please advice how to put the pieces together.
Thank you.
Valentin.
Firstly I would implement streams on your Image. This way you can create a constructor from a stream, and a method to create a stream to any of your ‘image’ subclasses.
Additionally, I would create your ‘saving’ infrastructure to simply accept streams and write them down onto your appropriate techniques (ftp, file etc.)
That way you end up with extensible images (if you can get a stream to it you can do many, many things) and you end up with a saving infrastructure that is extensible as well (anything that can go to a stream can be saved)
EDIT: Personally, a saving method on a data type object sounds like it’s in the wrong place, but without knowing your entire system I can’t say that for sure. Just my 2c.