To learn new things about software design, I often analyze .NET framework source codes.
During my study today the Microsoft.AspNetCore.Http.StatusCodes
class drew my attention when I saw it is not implemented as an enum, but rather as a static class with public const int
fields (not even properties).
Why would you not use an enum
for this purpose when it seems like a perfect solution? What might be the thought process behind this design decision?
I think I might be missing something here and I would be more than happy to learn something from this experience.
Here is an answer by Tratcher:
Status codes are not a closed set, any code between 100 and 999 is allowed. Enums work best for closed sets where all of the values are known. That enum does not even include all the standardized codes. It also has multiple entries for some codes. I've found the usability to be lacking as it obscures the actual status code from you.
Ref: https://github.com/aspnet/Mvc/issues/6997#issuecomment-388554278