Helping ordinary people create extraordinary websites!

Getting Started with Enumerated Types

By Brett McLaughlin
2005-04-22

Use Them, But Don't Abuse Them
One of the dangers of learning a new version of any language is the tendency to go crazy with new syntactical structures. Do that and suddenly your code is 80 percent generics, annotations, and enumerations. So use enumerations only where they make sense. Where, then, do they make sense? As a general rule, anywhere constants are in use, such as in places you are currently using the switch code to switch constants. If it's a single value (for example, an upper bound on a shoe size, or the maximum number of monkeys that can fit in a barrel), leave the constant as it is. But if you're defining a set of values, and any one of those values can be used for a certain data type, enumerations should be a perfect fit.



Tutorial pages:

First published by IBM developerWorks


 2 Votes

You might also want to check these out:


Leave a Comment on "Getting Started with Enumerated Types"
You must be logged in to post a comment.

Link to This Tutorial Page!


GET OUR NEWSLETTERS