Skip to content

Commit d6f11b9

Browse files
Explain domain layer better (#66)
1 parent 40401a4 commit d6f11b9

1 file changed

Lines changed: 0 additions & 12 deletions

File tree

README.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,30 @@ For now, we will focus on the purpose of the layers.
7272
![#gold](https://placehold.co/15x15/gold/gold.svg) **Domain Layer**
7373

7474
- **Domain model** is a set of concepts, rules and behaviors that define what business (context) is and how it operates.
75-
7675
It is expressed in a **ubiquitous language** — a consistent terminology shared by developers and domain experts.
77-
7876
Domain layer implements domain model in code; this implementation is often called domain model.
7977
- The strictest domain rules are **invariants** — conditions that must always hold true for the model.
80-
8178
Enforcing invariants means maintaining data consistency in the model.
82-
8379
This can be achieved through **encapsulation**, which hides internal state and couples data with behavior.
8480
- Building blocks of domain model are (not limited to these):
8581
- **value objects** — smart business types (no identity, immutable, equal by value).
8682
- **entities** — business objects (have identity and lifecycle, equal by identity).
8783
- **domain services** — containers for behavior that has no place in the components above.
8884
- Other domain model building blocks, unused in this project but important for deeper DDD:
8985
- **aggregates** — clusters of entities (1+) that must change together as a single unit,
90-
9186
managed exclusively through their root, defining boundaries of transactional consistency.
9287
- **repositories** — abstractions emulating collections of aggregate roots.
9388
- Domain model lies on a spectrum from anemic to rich.
9489
- **anemic** — simple data types, entities are just data holders, rules and behaviors live outside.
9590
- **rich** — value objects and entities encapsulate data and rules;
96-
9791
invariants are enforced internally, so the model itself prevents invalid states.
98-
9992
For components: anemic means no behavior within, rich — the contrary.
10093
- Domain services originally represent operations that don't naturally belong to a specific entity or value object.
101-
10294
But in projects with anemic entities, they can also contain logic that would otherwise be in those entities.
10395
- In the early stages of development when the domain model is not yet clearly defined,
104-
10596
I'd recommend keeping entities flat and anemic, even though the latter weakens encapsulation.
106-
10797
Once the core logic is well established, some entities can, as aggregate roots, become non-flat and rich.
108-
10998
This best enforces invariants but can be tricky to design once and for all.
110-
11199
- Prefer rich value objects early, freeing entities and services from an excessive burden of local rules.
112100
- Consider domain layer the most important, stable, and independent part of a system.
113101

0 commit comments

Comments
 (0)