DDD Is Not Folders Named Entities and Repositories: Start With Bounded Contexts
Entities, value objects and repositories are building blocks. Domain-Driven Design starts with the language, the core domain and the boundaries where each model applies.
The team "adopted DDD" last year. The Domain project has folders named Entities, ValueObjects, Aggregates and Repositories, and base classes for each. Then Support asks for VIP customers to skip the queue, and a developer sets IsVip on customers with many open tickets. The next morning Sales's pricing engine starts giving those customers the Gold discount. In Sales, VIP is a discount tier earned by spending; in Support, it means fast handling. Both meanings live in one Customer class that every team edits. The patterns are all there. The model isn't.
The common misconception
The belief: doing DDD means organizing code into Entities, Value Objects, Aggregates, Repositories and Domain Services, usually with folders and base classes named after them. A codebase that has them is domain-driven.
It's easy to see why. These patterns are the concrete, codeable part of Evans's 2003 book. Martin Fowler credits the book with classifying objects into Entities, Value Objects and Service Objects, which he calls the Evans Classification, and with identifying the concept of Aggregates, and says they "filled an important gap in thinking about objects". Templates and sample apps show the folders, and you can add folders on day one. Strategic design is about conversations and boundaries, which no template can generate.
The half-truth: the building blocks are genuinely part of DDD and genuinely useful. But they're tools for expressing a model in code. Without a model that the business recognizes, and a clear boundary around it, they're only class names.
What actually happens
Evans's own summary doesn't mention entities
The DDD Reference, Evans's summary of the patterns, describes Domain-Driven Design as an approach in which we "Focus on the core domain", "Explore models in a creative collaboration of domain practitioners and software practitioners", and "Speak a ubiquitous language within an explicitly bounded context." It adds that "Tactics and strategy must be combined to succeed". Fowler singles out strategic design, "how to organize large domains into a network of Bounded Contexts", as a particularly important part, and notes that DDD's core notions are conceptual and apply "with any programming approach".
One word, several models
Fowler's article starts from a utility company where "meter" meant subtly different things to different parts of the organization, and says the same confusion keeps recurring with words like "Customer" and "Product". Evans's conclusion, as Fowler quotes it: "total unification of the domain model for a large system will not be feasible or cost-effective". So DDD divides a large system into contexts, each with its own consistent model. The DDD Reference defines a bounded context as a boundary, "typically a subsystem, or the work of a particular team", within which a particular model is defined and applicable.
Microsoft's Azure guide gives a concrete case: drone repair needs a drone's maintenance history, mileage and age, while delivery scheduling only needs to know whether a drone is available and when. One model for both "introduces unnecessary complexity", so it's better to have two models of the same real-world drone.
The language is the model
Inside a context, the team builds a . Evans's instruction is to "Use the model as the backbone of a language" and to use it relentlessly "in all communication within the team and in the code." He also notes that "a change in the language is a change to the model." A folder called Entities says nothing in that language. Classes called Requester, ServiceLevel and DiscountTier do.
Not every part deserves the same effort
Evans says plainly that "not all parts of the design are going to be equally refined." His advice is to define a , "Make the core small", and justify investment elsewhere "by how it supports the distilled core." Microsoft's guide sorts subdomains into core, supporting and generic, and suggests generic ones, like user accounts, can use existing solutions. Aggregates and value objects everywhere, including plain CRUD screens, spread effort evenly where it should be concentrated.
The fix: one model per context, named in its language
C#
// Domain/Entities/Customer.cs: one class every team editspublic sealed class Customer : Entity{ public string Name { get; set; } = ""; // Sales public decimal CreditLimit { get; set; } public bool IsVip { get; set; } // Sales and Support both set this // Shipping public List<Address> Addresses { get; set; } = []; // Support public int OpenTickets { get; set; }}// All the patterns are here, but "VIP" means two things in one class
C#
namespace Sales{ // In Sales, a customer is someone we extend credit to public sealed class Customer(CustomerId id, Money creditLimit) { public CustomerId Id { get; } = id; public Money CreditLimit { get; private set; } = creditLimit; public DiscountTier Tier { get; private set; } = DiscountTier.Standard; }}namespace Support{ // In Support, the same person is a requester with a service level public sealed class Requester(CustomerId id, ServiceLevel level) { public CustomerId Id { get; } = id; public ServiceLevel Level { get; } = level; }}
The two contexts share an identity, CustomerId, and nothing else. Sales talks about discount tiers, Support about service levels, and neither can break the other by changing a flag. Where they must exchange data, the translation is explicit: Microsoft's guide lists relationships such as customer-supplier, open host service with a published language, and an anti-corruption layer that protects one model from another's changes. Inside each context, the tactical patterns still apply, and the next article in this path covers aggregates.
Myth
Reality
DDD means Entities, Value Objects, Aggregates and Repositories
Evans's summary: focus on the core domain, model with domain experts, speak a ubiquitous language in a bounded context
A company should have one Customer model
Evans: total unification for a large system "will not be feasible or cost-effective"
Folders named after patterns show the design
Names from the ubiquitous language show it; pattern names don't
Every part of the system deserves rich modeling
Make the core small and invest there; generic subdomains can use existing solutions
A bounded context is a microservice
It's a model boundary, typically a subsystem or a team's work; Fowler notes several can live in one application
How to apply it in your project
Map the domain with the people who know itSit with domain experts and sketch the business functions and how they connect, on a whiteboard or with event storming. Leave technology out of it.
Name the contexts and draw a context mapMark where words change meaning, name each context, and note how each pair exchanges data and who adapts to whom.
Classify and prioritizeLabel each subdomain core, supporting or generic. Spend your deepest modeling on the core, and consider existing products for generic parts.
Then apply the building blocksInside each context, name types in its language, and introduce aggregates and value objects where the rules justify them, not as a folder template.
Key takeaways
Entities, value objects and repositories are building blocks; DDD starts with the core domain, the language and the boundaries.
A bounded context is where one model and its language apply; the same word can mean different things in different contexts.
One company-wide model of a central concept is usually neither feasible nor cost-effective.
Put modeling effort into the core domain; generic parts can use simpler designs or existing products.
Use the tactical patterns inside a context, named in its language, not as folder names.
التعليقات (0)