Better to use a constructor or factory method template?

I have a wrapper class for a Bitmap class called BitmapZone.

Assuming we have a WIDTH x HEIGHT bitmap, this wrapper class should serve to allow me to send other methods / classes, rather than the original bitmap. Then I can better control what the user is or is not allowed to do with the image (and I do not need to copy the bitmap many times for sending for each method / class).

My question is: knowing that all BitmapZone are created from a bitmap, what do you prefer?

Constructor syntax: something like

BitmapZone bitmapZone = new BitmapZone(originalBitmap, x, y, width, height);

Factory Method Template:

BitmapZone bitmapZone = BitmapZone.From(originalBitmap, x , y, width, height);

Factory Method Template:

BitmapZone bitmapZone = BitmapZone.FromBitmap(originalBitmap, x, y, width, height);

Other? Why?

thank

+3
4

Bitmap BitmapZone.

BitmapZone bitmapZone = originalBitmap.GetZone(x, y)

: " BitmapZone ". , , , , -, .
 ( ? new BitmapZone(originalBitmap, x, y, originalBitmap.Width, originalBitmap.Height)? .)

Bitmap, (, , Java).

+1

. "" BitmapZone.

, . , , , . , .

+2

factory - . " Java" , - , #, .

+2

(BitmapZone.FromBitmap) , , , . , ; , . factory - .

, .

+1

Source: https://habr.com/ru/post/1743681/


All Articles