我将建设将涉及到“应用程序”的不同状态之间切换了大量的软件。某些任务可以完成取决于应用程序所处的状态。我想使用枚举的状态枚举VS查找表VS枚举反射VS State模式
public class Application
{
public int Id {get;set;}
public Status {get;set;}
}
public enum Status
{
[Description("New")]New = 1, [Description("Closed")]Closed = 2
}
但转念一想,也许这是很好用的查找表在数据库中的地位不会得到更新/重新排序往往
table status (id int pk, desc string, sort_order int)
table application (id int pk, status_id int fk)
在我case我需要做的事情,如
if (application.Status == Status.New)
{ //do something }
else if (application.Status == Status.Closed)
{ //do other things }
我认为上面的情况是更容易做与枚举。但是,当涉及到更新状态排序顺序或描述时,这将非常困难。
我应该用反射基于从查找表值来动态创建枚举?或者我应该使用状态模式?我看到与枚举重新感谢问题是性能影响。状态模式会产生大量的冗余代码。
您认为如何?提前致谢!
您是如何从数据库处理检索和转换为对象如果我在答案3中提到,否则没有其他陈述? – Jeff 2009-03-04 09:58:15