Skip to content
Low Level Design Mastery Logo
LowLevelDesign Mastery

Enums

Create type-safe named constants with enums.

Enums (enumerations) are a way to define a set of named constants. They provide type safety and make code more readable by using meaningful names instead of magic numbers or strings.

An enum is a special type that represents a fixed set of constants. Instead of using arbitrary numbers or strings, enums allow you to use meaningful names.

  • Type Safety - Prevents invalid values
  • Readability - Code is self-documenting
  • Maintainability - Easy to update values in one place
  • IDE Support - Better autocomplete and refactoring

Different languages implement enums in different ways:

Enums can use integer values:

Enums can have methods and properties:

You can iterate over all enum values:

Diagram

Use enums when:

  • You have a fixed set of related constants
  • You want type safety (prevent invalid values)
  • You need self-documenting code
  • Values won’t change frequently
  • You want better IDE support

Examples:

  • Status values (PENDING, ACTIVE, INACTIVE)
  • Days of the week
  • Colors
  • Priority levels
  • Error codes
  • Configuration options

💡 Time to Practice!

Now that you understand the concepts, put them into practice with our interactive playground. Build UML diagrams, write code, and get AI-powered feedback.

Browse All Problems