Transforming Conditionals to Polymorphism?

I would take all it arguments as parameters. Don't use static variables as argument if you can.

I would take all it arguments as parameters. Don't use static variables as argument if you can. Public static Bitmap getFooterBitmap(int width, int height){ String filename = width == 360 && height == 480?"360x480" : "320x240"; return Bitmap.

GetBitmapResource(filename+"/footer_bp. Png); } Using polymorphism is a good idea but not the best solution in every situation. Another approach might be to see if the size is available and use a fall back position.

Public static Bitmap getFooterBitmap(int width, int height){ Bitmap bm = Bitmap. GetBitmapResource(width+"x"+height+"/footer_bp. Png); if (bm == null) bm = Bitmap.

GetBitmapResource("320x240/footer_bp. Png); return bm; }.

– user470184 Jun 3 at 13:42 I don't think I can use a Ternary operator in this case, as the list of conditionals is bound to grow to more than two over time, I should have mentioned this in the question. – user470184 Jun 3 at 13:43 +1 for "not the best solution in every situation." - If you set out dogmatically replace all your conditional code with polymorphism, you're likely to make your code more, rather than less, difficult to maintain. – DaveHowes Jun 3 at 13:44 1 @user - in your original example, your factory method does not take any arguments.

Which means that the "displayWidth" and "displayHeight" variables must be static variables of the FactoryClass.In that case you will run into concurrency problems if two threads attempt to use the the factory method at the same time. I think that is what Peter was alluding to. – DaveHowes Jun 3 at 13:46.

Don't reference the widths in code, instead get the potential filename from the display size. String filename = width + "x" + height Now look for file of those particular dimensions. If it exists, use it, otherwise fall back on 320x240.

This way you don't have to keep your code in sync with the list of files.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions