How can I refactor that code ? (state pattern ?)
Posted
by alex
on Stack Overflow
See other posts from Stack Overflow
or by alex
Published on 2010-05-19T10:34:24Z
Indexed on
2010/05/19
10:40 UTC
Read the original article
Hit count: 250
Hello guys,
How can I refactor that code ?
public enum enum1
{
value1 = 0x01,
value2 = 0x02,
value3 = 0x03,
value4 = 0x04,
value5 = 0x05,
UNKNOWN = 0xFF
}
class class1
{
private const string STR_VALUE1 = "some text description of value1";
private const string STR_VALUE2 = "some text description of value2";
private const string STR_VALUE3 = "some text description of value3";
private const string STR_VALUE4 = "some text description of value4";
private const string STR_VALUE5 = "some text description of value5";
private const string STR_VALUE6 = "some text description of unknown type";
public static string GetStringByTypeCode(enum1 type)
{
switch(type)
{
case enum1.value1:
return STR_VALUE1;
case enum1.value2:
return STR_VALUE2;
case enum1.value3:
return STR_VALUE3;
case enum1.value4:
return STR_VALUE4;
case enum1.value5:
return STR_VALUE5;
default:
return STR_VALUE6;
}
}
}
PS: there are many enum1...enumX and GetStringByTypeCode(enum1) ... GetStringByTypeCode(enumX) methods.
© Stack Overflow or respective owner