public 静态 class 或常量

public static class or const

我应该创建一个 public 静态 class 还是使用内部常量? 我正在处理一个非常大的应用程序,并注意到在众多 places.This 处使用 const 字符串用于比较用户选择

const string Thatch = "Thatch";
const string BrickAndTimberFrame= "Brick And Timber Frame";
const string OtherRoof = "Other";
etc......
etc......

我想要做的是在核心应用程序中创建 public 静态 class(请参阅下面的代码)。这样做的原因是我只需要 change/add 一个地方的值。

public static class RoofConstruction
{
  public static String Thatch{ get { return "Thatch"; } }
  public static String BrickAndTimberFrame { get { return "Brick And  Timber   Frame"; } }
  etc....
  etc....
}

比较函数将如下所示

 internal bool SlateTileOrConcreteRoof()
        {
            return RiskInformation.RoofConstruction.Value == RoofConstruction.Slate ||
                   RiskInformation.RoofConstruction == RoofConstruction.TileAndSlate ||
                   RiskInformation.RoofConstruction == RoofConstruction.Concrete;
        }

请添加任何comments/improvements等

一般来说,我认为“'好Class™'的定义特征”是“它正确的事情,没关系(!)“到底是怎么做到的,” 它是这样做的。”

当您从 class 导出 constants 时,这表明应用程序 (现在和未来 . ..) 将包含针对该字符串进行测试的逻辑。

因此,只有您才能真正回答的问题:“他们真的关心‘该字符串的值’,还是他们想要‘是或否问题的答案,答案在部分基于该字符串的值?'”这可能会指导您决定最好做什么。 (请注意,我不认为存在任何明确的规则。我两种方式都做到了...)