Domain-Driven Design

Model the code on the business, in the business's own words. Know the building blocks (entities, value objects, aggregates, repositories, events) and where to draw the boundaries.

Overview

Domain-Driven Design (DDD) is a way of building software where the shape of the code follows the shape of the business problem. Eric Evans described it in *Domain-Driven Design: Tackling Complexity in the Heart of Software* (Addison-Wesley, 2003). The book has two halves. The strategic half is about drawing boundaries between models in a large system. The tactical half is a set of building blocks for one model: entities, value objects, aggregates, repositories, domain services, domain events and factories.

Low-level design interviews borrow the tactical half heavily. When an interviewer says 'design the classes for an order system', they listen for whether you separate things with identity from things without it, whether you know which objects must change together, and whether business rules live in the domain objects or leak into service classes.

Two halves of DDD

Each half answers a different question. The strategic half asks where one model ends and another begins, and its main tools are the bounded context, the context map and the ubiquitous language. The tactical half asks what the objects inside one model are, and its tools are the entity, value object, aggregate, repository, domain service, domain event and factory. The strategic half starts with words, so that is where this chapter starts too.

Interview questions

  • What is the difference between an entity and a value object? Show it in code.
  • What is an aggregate, and how do you choose its boundary?
  • What is a bounded context, and how do two contexts talk to each other?
  • What is a repository, and how is it different from putting SQL in the domain class?
  • What is a domain event, and why would you use one instead of a direct call?

Sign up free to read the full topic

More Low-Level Design topics

Start free on Cariara · Coding problems · System design studio