liveBook · Manning

Enum

As explained in Grokking Software Architecture

A programming-language type that restricts a value to a predefined set of named options.

An enum can replace an opaque numeric code with a meaningful named option. In a moderation request, “Spam” is clearer than the number 4. section 6.5.2

{                           
  "flaggedCommentId": 101,
  "reasonType": "Spam",    // Enums are self-documenting prompts!
  "moderatorNote": "x99"
}

A descriptive reasonType makes the moderation request easier to interpret than a cryptic field and numeric value. section 6.5.2

How Grokking Software Architecture covers it

How deep it goes
Shows a string enum in a DTO and recommends integer status codes referencing an enum, without detailing implementation.
Examples
Uses a moderation DTO whose reason is “Spam” rather than numeric code 4.
What you can do after
Apply descriptive enum labels to make API values easier for AI to interpret, and reference enums for database status codes.
How it connects
Links enums with API DTOs, magic numbers, and database column types.

Also explained in

Compare how 25 books explain enum →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Software Architecture. The section links point to the parts of the book it draws on.