What are the advantages (or disadvantages) of having an enum
versus having a set of static final int
s in Java Android applications? Are there efficienc
One advantage of ints over enums is in a CLASS FACTORY. The following C# code is not extensible:
class Factory
{
public enum DrawableType {CIRCLE,SQUARE};
public static Drawable GetInstance(DrawableEnum e)
{
if (e == DrawableType.CIRCLE)
{
return new Circle();
}
else if (e == DrawableType.SQUARE)
{
return new Square();
}
else
{
throw new IndexOutOfRangeException(); // should never get here
}
}
I wrote this poor code. Reviewing Design Patterns, the gang of four used an int. I tried to recover here.