Plenty of C++ business code treats the domain as data to be shuffled. The rules end up in managers and validators, three call layers away from the field they protect, so a referral that spells `CARDIOLGY` reaches the database, two appointments land in room R4 at 10:30, and an override moves someone's follow-up with no trace of why.
Domain-Driven Design has an answer for each of those three. Almost all of its literature assumes a managed runtime, and I could not find the ideas worked out in modern C++. So I wrote this book.
What you get out of it
- Fewer surprises after dark. A rule that lives in a type fails at build time, long before anyone stands outside room R4 waiting for a bed. A rule that needs live data fails at runtime, at a boundary you built to refuse it. Every chapter says which one it's handing you.
- A vocabulary you can grep. The clinic's language becomes an `enum class` with twelve members, a name table with twelve rows, and a parser that refuses a thirteenth. A forgotten `case` stops the build, because `-Werror=switch` sits in every snapshot's own `CMakeLists.txt`. New developers on your team read the type and learn the domain.
- Boundaries the build respects. Five bounded contexts, mirrored in namespaces and CMake targets, so code that reaches across a border fails on your machine. It doesn't wait for a reviewer to notice.
- Failures that carry their reason. Business refusals come back as values through `std::expected`, chained with `and_then` and `or_else`, then translated once, at the edge, by an exhaustive switch that maps every domain failure to an HTTP status. The messages name the failure and not the patient, which is a privacy decision and not an oversight. Exceptions stay reserved for genuine faults.
- Proof that an abstraction is free. Size, trivial copyability and compile-time evaluation get pinned by `static_assert`, and the loops that could drift get timed with the numbers printed. A wrapper that costs nothing becomes something you measured.
- Judgment, and a way in. Chapter 15 scores twelve patterns against the eight failures and labels the ceremony as ceremony, so you can turn a pattern down with a reason instead of a preference. Chapter 16 then works a legacy codebase from the lowest-risk rung up, with a strangler seam at the booking boundary and no rewrite.
How the book is built
Sixteen chapters, one running example, five parts. Chapters 2 to 16 each ship a buildable snapshot with passing tests.
- Part I, Orientation and strategy (chapters 1 to 2). The clinic, its people, its diary rules and its invented Tuesday, then the bounded contexts and the shared kernel that decide where a rule is even allowed to live.
- Part II, The type system as a modeling tool (chapters 3 to 7). Closed vocabularies and exhaustive switches, a `TimeRange` that can't be inverted, rules that return instead of throw, identity that survives a rename, and the zero-cost contracts you prove rather than assume.
- Part III, Behavior behind boundaries (chapters 8 to 11). An aggregate with one way in and no public setters, cross-aggregate policy values and overrides with recorded reasons, a repository port specified as a concept, and domain events dispatched after commit.
- Part IV, Architecture in the compiler (chapters 12 to 14). Contexts turned into C++20 modules, read models materialized once, and a coroutine intake flow that compensates cleanly when a step fails.
- Part V, Judgment (chapters 15 to 16). The audit, then the adoption path for code you inherited.
Front matter sets the conventions and the toolchain. The back matter carries setup steps, a cheat sheet, numbered further reading, the solutions index, and a glossary of ninety-eight terms.
The code
Fifteen chapter snapshots, one per chapter from 2 to 16, each a small CMake project with tests that pass. They build warnings-clean under `-Wall -Wextra -Wpedantic`. Demo output quoted in the chapters comes from real runs, and each diagnostic names the compiler that printed it, because wording travels badly between compilers. Where a claim needs a number, a number sits beside it.
Who it's for
C++ developers who want the business rules inside the model. Java and C# readers who've met the Blue Book and don't want to trade predictability for a managed runtime. Senior developers weighing C++23 for a domain-heavy system. You don't need a DDD background, since chapter 1 brings it, but you do need to be comfortable with C++ at a working level. This isn't beginner's book, and chapter 1 teaches a clinic rather than variables.
Ninety-seven exercises, sorted into recall, application and extension, each with a worked solution.
What isn't in it
Full event-sourced persistence, ORM-backed storage, distributed microservices. Tests and demos run against an in-memory repository, and the mock database adapter is a sketch that deliberately never compiles. I'd rather say so here than have you meet it in chapter 10.
C++ is a business language too. This book puts the rules where the compiler can help you keep them.