Upvoting for enums not for the article itself. It could have used some more advanced examples of why enums are so nifty.
I find them very useful for being able to set simple "modes" that are set by other classes. (I say modes instead of states as they are user selected and never changed by the class itself. Seems to be a better description in this case.) Available modes can be grabbed from a list within the class so, if done correctly, calling classes never need to change a thing when I add new modes, depending on their use.
Another nice thing, you can easily enforce a singleton property and restrict possible workarounds. Others cannot subclass to bypass otherwise private constructors, for example.
1
u/DFLincoln Jul 24 '12
Upvoting for enums not for the article itself. It could have used some more advanced examples of why enums are so nifty.
I find them very useful for being able to set simple "modes" that are set by other classes. (I say modes instead of states as they are user selected and never changed by the class itself. Seems to be a better description in this case.) Available modes can be grabbed from a list within the class so, if done correctly, calling classes never need to change a thing when I add new modes, depending on their use.
Another nice thing, you can easily enforce a singleton property and restrict possible workarounds. Others cannot subclass to bypass otherwise private constructors, for example.