[geeks] OO class design question
Joshua D Boyd
jdboyd at cs.millersville.edu
Thu Oct 17 14:12:59 CDT 2002
Well, I'm as rapidly as I can trying to learn lots of things at once,
for a variety of tasks, most of which are related to my graphics class.
So, perhaps this question is answered later in one of the books I'm
reading, but it didn't jump out at me from table of contents in
anything.
So, I have several instances that fit this pattern, but I'm just going
to pick one as an example.
I have a class Image. Image contains all the metadata I need about the
image, like width, heighth, pixel format, etc, in addition to the image
data itself. Now, there are several ways that I could get an image. I
could load it from a tiff or a jpeg. I could create it from the txsynth
library. I could create it using some other procedural method. I could
save into the image class from the screen.
So, this causes me to rethink how I get data into the image. Before I
might have subclassed Image to classes like JpegImage, TiffImage, etc.
But, I really don't care where the image came from once it is loaded, so
it seems silly to include all the extras that JpegImage provides.
Another possibility (the one I'm using at the moment is to use something
like:
Image * img = LoadJPG(filename);
where LoadJPG is a function that returns a new Image class. It works,
but it leads to duplicating mechanisms that would also be shared with
LoadTIFF and LoadTGA, and it just doesn't seem like the proper OO thing
to do.
--
Joshua D. Boyd
PS, yes I did try asking about this at school, and got asked why I was
wasting my time on classes instead of just making something work
quickly.
More information about the geeks
mailing list