Note that there are some explanatory texts on larger screens.

plurals
  1. POToo many attributes on enum?
    text
    copied!<p>My system currently runs in differents environments.</p> <p>I got a Environment enum on my system, something like this</p> <pre><code>public enum Environment { [UsePayPal(false)] [ServerInstallDir("InstallPathOnServer")] [IntegrationSystemURI("localhost/someFakeURI")] [UpdateSomeInfo(true)] [QueuePrefix("DEV")] [UseCache(false)] [AnotherSystemURI("localhost/anotherFakeURI")] Development = 0, [UsePayPal(false)] [ServerInstallDir("InstallPathOnBUILDServer")] [IntegrationSystemURI("build-server/someFakeURI")] [UpdateSomeInfo(true)] [QueuePrefix("QA")] [UseCache(false)] [AnotherSystemURI("build-server/anotherFakeURI")] QA = 1, [UsePayPal(true)] [ServerInstallDir("InstallPathOnServer")] [IntegrationSystemURI("someservice.com/URI")] [UpdateSomeInfo(true)] [QueuePrefix("PRD")] [UseCache(true)] [AnotherSystemURI("anotherservice/URI")] Production = 2, } </code></pre> <p>I'm working like this, because I dont like code like</p> <pre><code>if(CURRENT_ENVIRONMENT == Environment.QA || CURRENT_ENVIRONMENT == Environment.DEV) EnableCache() </code></pre> <p>or</p> <pre><code>if(CURRENT_ENVIRONMENT == Environment.QA || CURRENT_ENVIRONMENT == Environment.DEV){ DoSomeStuff(); } </code></pre> <p>because I think that's scatter my logic all over the system, and not on a single point. </p> <p>If some day I add another Test Enviroment, I dont need to go all over my code to see if I work like on Development, QA or Production enviroment.</p> <p>Ok, but, with all that config I may end up with too maby attributes on my Enum, lets say, in 3 years each enum value will have 15~20 attributes, and that looks weird.</p> <p>What do you guys think? How do you usually handle this situation? Its really too many attributes, or thats ok?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload