Use an enumeration when an attribute has a limited set of named values. For book genres, Genre replaces strings with constants such as ADVENTURE, CLASSICS, HORROR, and SCIFI. section 2.3.2
Compared with strings, an enumeration provides:
- Compiler-detectable misspellings of named constants. section 2.3.2
- Efficient run-time comparisons between known values. section 2.3.2
Book genres
A book can store Genre::ADVENTURE or Genre::CLASSICS instead of a genre string. A catalogue can then search for Genre::HORROR without handling capitalization or spelling variations.






















