What Is an Enum?

An enum (enumeration) is a special type that represents a fixed set of named values.
Instead of using raw integers or strings for states (like 0, 1, "CREATED", "DONE"), you give each possible value a clear, descriptive name.

Examples of things that are naturally enums:

  • Order status: created, confirmed, cancelled, refunded

  • Ticket status: booked, checked‑in, expired

  • User role: admin, moderator, regular user

  • Payment method: card, UPI, net banking, cash

Enums are very useful in LLD because many systems have concepts with a limited set of allowed values.
Modeling those as enums makes your design clearer and harder to misuse.

Why Use Enums Instead of Strings or Integers?

Without enums, beginners often represent states like this:

  • Integers: status = 0 (for created), status = 1 (for confirmed), status = 2 (for cancelled)

  • Strings: status = "CREATED", status = "CONFIRMED"

This has problems:

  • Integers are not self‑explanatory: what does 2 mean?

  • Strings are error‑prone: "CREATED", "Created", "CRETAED" (typo) All compile, but some are wrong.

  • Changing or searching all raw strings later is harder.

With enums:

  • Each possible value has a named constant.

  • The compiler can catch invalid values and type mismatches.

  • The intention is immediately clear when you read the code.

In LLD, enums make your class diagrams and designs more expressive because you can say “this class has a status attribute of type OrderStatus”, which is much clearer than int or string.

Basic Enum Syntax in C++

Unscoped enum (older style)

A simple C++ enum:

Here:

  • OrderStatus is the enum type.

  • CREATED, CONFIRMED, CANCELLED are possible values.

You can use it like this:

Internally, these values are usually stored as integers (0, 1, 2), but you use the names.

However, unscoped enums can pollute the global namespace (names like these CREATED are visible everywhere), which can cause name collisions in bigger codebases.

Scoped Enums with enum class

Modern C++ introduced scoped enums (enum class) which are safer and recommended in most new code.

Example:

Key differences:

  • Values are now accessed with the enum name as a scope:


  • They do not implicitly convert toint, which avoids many subtle bugs.

  • Names are better organized (no globalCREATED, you have OrderStatus::CREATED).

For LLD code and interview examples, it enum class is usually the better choice to demonstrate a clean, modern style.

Using Enums Inside Classes

Enums are often used as the type of a class attribute representing a state.

Consider a simplified Booking class for a cab booking app:

Here:It

  • BookingStatus is an enum that clearly captures the allowed states of a booking.

  • The The The Booking class uses this enum to manage valid transitions between states.

This is exactly how enums appear inside LLD solutions: as a strong, self‑documenting type for states.


Example: Creating and Checking Enum Values

Using the previous Booking class:

This shows:

  • How an enum value is stored inside a class.

  • How methods update the enum field as the object progresses through different states.

  • How can the calling code check the final status by comparing against enum constants?

There is no confusion about what BookingStatus::COMPLETED means, unlike using an integer like 3.

Enums for Roles, Types, and Categories

Enums are not just for lifecycle states; they are also useful for roles and categories.

Example: a very simple user role design:

Usage:

Enums make it very clear what roles exist and what behaviors are allowed for each.

Converting Enums to Integers or Strings (When Needed)

Sometimes you need to log the status or store it in a database.
Enums do not automatically print as text, so you may convert them manually.

Example helper for BookingStatus:

Use in code:

For LLD interviews, it is enough to show that you understand:

  • Enums are stored in variables.

  • You can compare them in if or switch.

  • You can create helpers to convert them to other forms when needed.

Where to Declare Enums in LLD

When designing classes and enums together, some simple guidelines help keep the design clean:

  • If an enum is used only by one class and is tightly tied to it (like a specific State of a class), You can keep it near that class in the same header or file.

  • If an enum is used across multiple classes (e.g., UserRole used by many classes like User, AuthorizationService, Logger), consider placing it in a shared header.

From an LLD perspective, you might say:

  • “The The The Booking entity has a status attribute of type BookingStatus enum.”

  • “The The The User entity has a role attribute of type UserRole enum.”

This keeps your design notation clear and consistent.

Common Mistakes with Enums

Beginners often run into a few predictable issues:

  • Still using raw integers instead of enums

    • For example, using int status = 1; an enum type instead.

    • This reduces readability and increases bugs.

  • Using strings everywhere for state

    • Strings are easy to mistype and slower to compare.

    • Enums give you compile‑time checking and clear value lists.

  • Not covering all enum values in switch

    • Always add a default: case or handle each enum explicitly.

  • Overloading enums

    • Putting too many unrelated meanings into a single enum (for example, mixing order lifecycle and payment outcome in the same enum).

    • Better: separate enums like OrderStatus and PaymentStatus.

Being aware of these helps you use enums effectively in your LLD solutions.

Summary

Enums represent a fixed set of named values and are a powerful tool for modeling states, roles, and categories in Low Level Design.
They replace unclear integers and fragile strings with meaningful, type‑safe names.

You learned:

  • What enums are and why they are useful in LLD.

  • The difference between unscoped enum and enum class in C++.

  • How to define enums and use them inside your classes.

  • How objects change their enum fields as they move through different states.

  • How enums fit naturally into real examples like cab booking and user roles, and what pitfalls to avoid.