@@ -115,8 +115,7 @@ image::hexagonal_component_architecture_overview.drawio.svg["devonfw hexagonal a
115115 ├── ReservationJpaMapper.java
116116 └── TableJpaMapper.java
117117----
118-
119- [cols="1,1", options="header"]
118+ [cols="20,~", options="header"]
120119|===
121120| Package | Description
122121
@@ -126,7 +125,7 @@ image::hexagonal_component_architecture_overview.drawio.svg["devonfw hexagonal a
126125| core.domain
127126| The domain circle contains the entities and value objects of the business domain of the application.
128127Related Factories or Builders are located here as well.
129- The entities in our domain are usually rich.
128+ It's proposed to make entities anemic. See <<_anemic_vs_rich_domain_models>>
130129
131130| core.usecase
132131| Use Cases are the main entrypoint of the applications core.
@@ -191,3 +190,29 @@ Inside the adapters further packages are differentiating the protocols that is u
191190That can be database connections, file operations, API calls, message producing and many more.
192191Inside the adapters further packages are differentiating the protocols that is used (e.g. `.jpa`).
193192|===
193+
194+
195+ == Anemic vs Rich domain models
196+ ====
197+ "In a rich domain model, as much of the domain logic as possible is implemented within the entities at the core of the application.
198+ The entities provide methods to change state and only allow changes that are valid according to the business rules. [...]
199+ In an “anemic” domain model, the entities themselves are very thin.
200+ They usually only provide fields to hold." <<Hombergs21>>
201+ ====
202+
203+ Considering java as an object oriented language it feels natural to implement business logic inside the entities themselves.
204+ In large scale application with mixed skilled people it's proposed to not use rich domain models.
205+ There are two reasons for this.
206+ First of all, the domain objects are returned to the adapters.
207+ If they include business logic this is revealed and available outside of the core, which should not be the case.
208+ The answer to this problem could be an additional mapping, but this leads to a lot of unpractical mappings.
209+ Furthermore, adding the business logic to the domain entities spreads it across use cases, entities and services.
210+ This makes the application more difficult to understand and harder to locate the place for new features or changes.
211+
212+ It's proposed to implement the domain model as anemic entities using Java records.
213+ Use use cases and services to implement the business logic and interact with the domain models.
214+
215+
216+ [bibliography]
217+ == Bibliography
218+ * [[[Hombergs21]]] Tom Hombergs. _Get Your Hands Dirty on Clean Architecture._ 2021.
0 commit comments