Proposed draft for the thumbnail D-Bus specification
Philip Van Hoof
spam at pvanhoof.be
Wed Sep 10 03:42:07 PDT 2008
On Wed, 2008-09-10 at 11:49 +0200, Philip Van Hoof wrote:
> have been trying to explain us that a class must
> be good at doing one thing ... but only one thing.
I mis worded this, it's rather
"being good at being one thing" not "being good at doing one thing".
It's small difference in words, but if of course has a different
meaning.
Of course can a class do more than one thing. Just like how a horse can
both run and memorize.
> A class must not try to solve the world.
Just like a horse wont solve the world, yet it's good at being a horse
My point is:
A thumbnailer must be good at being a thumbnailer.
A thumbnailer must not try to be good at being both a generic resizer
and a thumbnailer.
A thumbnailer could consume a generic resizer, to avoid said code
duplication. Of course. But that's still two different classes of
things.
So:
public interface Resizable {
public string mime_type;
}
public interface Resizer {
pixmap resize (Resizable r, int width, int height)
}
public class ImageResizer : Resizer {
public pixmap resize (Resizable r) {
Requires {
typeof (r) extends (Image)
}
}
}
public interface Thumbnailer {
HashTable <string, Resizer> performers;
public void Queue (Resizable r) {
pixmap = performers[r.mime_type].resize (r, 256, 256)
save (pixmap, large_path)
pixmap = performers[r.mime_type].resize (r, 128, 128)
save (pixmap, normal_path)
}
}
And not:
public interface Thumbnailer {
public void Queue (Resizable r, int width, int height, out pixmap p) {
// Required magic if-then-else, making decisions
// behind your back
if (width < 256) {
do thumbnailing
p = get_from_image (thumbnail_path)
} else {
do resizing
p = get_from_memory ()
}
}
}
--
Philip Van Hoof, freelance software developer
home: me at pvanhoof dot be
gnome: pvanhoof at gnome dot org
http://pvanhoof.be/blog
http://codeminded.be
More information about the xdg
mailing list