|
Helping ordinary people create extraordinary websites! |
Getting Started with Enumerated TypesBy Brett McLaughlin2005-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: » Represent Constants in a Typesafe Manner Using Java 5.0 » Defining an Enum » Working with Enumerated Values » Enums and Collections » Going Further » Use Them, But Don't Abuse Them » Resources First published by IBM developerWorks |
|