In module 4.2 you cut the Kladde into contexts, wrote a glossary and drew a context map. Those were the boundaries. In this module you build what lies inside the boundaries: the models. The tool for that is called tactical DDD. It consists of a few building blocks: entities, value objects, aggregates, domain events and domain services. On top comes an architecture that protects the model from everything technical, ports and adapters.
You start with the Quotes context. The Kladde doesn't have it yet, so you build it right from the start. The appointments from K2
follow in lesson 4.3.7, where you learn how to bring existing code into the same shape. In this lesson, the smallest building blocks come into being,
the value objects Money, Quantity, QuoteId and TenantId, each with tests.
Two kinds of things
Look at two sentences from the everyday life of the IT office:
- “Ms. Feld has been called Feld-Ostrowski since she got married.” It is the same person as before. Her name has changed, she herself hasn't.
- “The hourly rate rises from 95 to 105 euros.” Nobody says the 95 euros turned into 105 euros. It is simply a different amount.
The first sentence is about something with an identity. It stays the same even when all of its properties change. In the model, something like that is called an entity. The second sentence is about a value. A value has no identity: two amounts of 95 euros are equal, and it doesn't matter which of the two you hold in your hand. In the model, something like that is called a value object.
You don't change a value object, you replace it. The hourly rate of a line gets a new amount. The old amount isn't modified in the process, it just isn't used anymore.
| Term in the Kladde | Kind | Why |
|---|---|---|
Contact (Contact) |
entity | stays the same person, even with a new name and a new address |
Email address (EmailAddress, since K1) |
value object | two equal addresses are equal; a new address replaces the old one |
Quote (Quote) |
entity | has a number, a history and a state that changes |
Amount (Money) |
value object | 95.00 euros are 95.00 euros |
Quantity (Quantity) |
value object | 2.5 hours are 2.5 hours |
| Time span of an appointment | value object | start and end together, without an identity of their own |
Office as a tenant (TenantId) |
value object | the identifier of an office; the office itself is an entity in another context |
Whether something is an entity or a value depends on the context, not on the word. An address is a value in a quote: it appears there the way it was when the quote was sent. For a parcel service planning its delivery districts, the same address may be an entity with a number of its own. So always ask: Does the domain expert care which one it is, or only what it is?