Reputation: 53826
I'm adding images to screens depending on screen resolution. So depending on the screen resolution I add the approprate sized image. Does this fall into any design pattern? Or is there a design pattern that better suits this requirement ?
ImageFactory.getBitmap();
public static Bitmap getBitmap(){
if(screenWidth == 360 && screenHeight== 480){
return new Bitmap("360480.bmp");
}
else {
return new Bitmap("320240.bmp");
}
}
Upvotes: 1
Views: 174
Reputation: 1898
It looks like, in this particular case, you can get away with convention strategy (not as a design pattern).
Something like this:
public static Bitmap getBitmap(){
String fileName = Integer.toString(screenWidth)
+ Integer.toString(screenHeight) + ".bmp"
File f = new File(fileName);
if(f.exists()){
return new Bitmap(fileName);
}
else {
return new Bitmap("320240.bmp");
}
}
Upvotes: 1
Reputation: 10487
This looks like a factory pattern. Your factory is smart about which bitmaps to create/return by taking the screen size into account, and from what I'm seeing I think you are doing alright there.
While you are at it, you might want to think about the naming pattern for the images (I think something like "640x480.bmp" is easier to the eye than "640480.bmp").
Upvotes: 1