I have an enumeration that looks like
public enum MyEnum
{
myValue
{
@Override
public String myMethod(String dostuff)
{
return dostuff + "One";
}
},
myOtherValue
{
@Override
public String myMethod(String dostuff)
{
return dostuff + "Two";
}
},
aThirdValue
{
@Override
public String myMethod(String dostuff)
{
return dostuff + "Three";
}
};
public abstract String myMethod(String dostuff);
}
Now I think we can all agree that this looks awful? but what would be the best way? I could have an abstractfactory, but then I need three implementation classes, each of which will be used as a single-line method. I do not think so beautiful. I could use a switch (either in code or in enumeration). But then I could forget to add a case.
So how to go? There must be a sample for this, but it does not seem to be found. So far, the best ive has come up with to add comments to Netbeans autocomplete methods, not so brilliant as they are.
source
share