我将要构建的软件将涉及很多不同状态之间的“应用程序”切换。可以完成的某些任务取决于应用程序所处的状态。我正在考虑使用枚举作为状态
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)
就我而言,我需要做类似的事情
if (application.Status == Status.New)
{ //do something }
else if (application.Status == Status.Closed)
{ //do other things }
我认为使用枚举更容易实现上述情况。但是,当涉及到更新状态排序顺序或描述时,它会非常困难。
我应该使用反射根据查找表中的值动态创建枚举吗?或者我应该使用状态模式?我看到枚举相关的问题是性能影响。而状态模式会产生大量的冗余代码。
你怎么看?提前致谢!