vendredi 23 novembre 2018

Enums vs string constants c#

So I have recently read a book specifically on Dependency Injection. In this book, somewhere, it states that enums are a code smell....

I wanted to get a general consensus from SO'ers. I need to design a rather large application with some central core classes, and am seeking assistance in terms design principles that fellow SO'ers would use in this instance, before committing myself to one way or the other making it very difficult to change afterwards.

public enum Foo
{
  LovelyFoo,
  TerribleFoo
}

OR

Using a static class with Contants

    public static class Foo
    {
    public const string LovelyFoo = nameof(LovelyFoo); //or "Lovely Foo";
    public const string TerribleFoo = nameof(TerribleFoo); // or "Terrible Foo";
    }
}

Then Of course using it when required

Foo MyFoo = Foo.LovelyFoo;

OR

string MyFoo = Foo.LovelyFoo;

Aucun commentaire:

Enregistrer un commentaire