I have a wrapper class for the Bitmap class called BitmapZone.
Assuming we have a WIDTH x HEIGHT bitmap picture, this wrapper class should serve the purpose of allowing me to send to other methods/classes itself instead of the original bitmap. I can then better control what the user is or not allowed to do with the picture (and I don’t have to copy the bitmap lots of times to send for each method/class).
My question is: knowing that all BitmapZone’s are created from a Bitmap, what do you find preferrable?
Constructor syntax: something like
BitmapZone bitmapZone = new BitmapZone(originalBitmap, x, y, width, height);
Factory Method Pattern:
BitmapZone bitmapZone = BitmapZone.From(originalBitmap, x , y, width, height);
Factory Method Pattern:
BitmapZone bitmapZone = BitmapZone.FromBitmap(originalBitmap, x, y, width, height);
Other? Why?
Thanks
Put the method in
Bitmapinstead ofBitmapZone.You said it yourself: “Each BitmapZone is created from a Bitmap”. This way you go from five parameters to two, since you don’t need to pass in the bitmap, and each bitmap presumably knows its own width and height.
(How were you going to do that otherwise?
new BitmapZone(originalBitmap, x, y, originalBitmap.Width, originalBitmap.Height)? Ugly.)If you can’t change the Bitmap class, make it an extension method (though of course, that wouldn’t work in Java).