Appendix E. Tactical Refactorings That Strengthen Domain Knowledge
Code that makes it hard to understand for what purpose it was built also makes it hard to maintain. Therefore we want our code to clearly express the concepts of the domain it is built for. The refactorings in this appendix are meant to help you transform muddy code into crisply expressed concepts that make it easy for the reading programmer to understand and change them.
To achieve this beautiful and behavior rich domain model, different actions can be taken:
-
Bring domain language into the code with Enforce Ubiquitous Language.
-
Make the domain model more expressive through Replace Primitive with Value Object, Heal Entity Anemia, and Introduce Contract.
-
Separate business logic from technical code with Split Active Record into Aggregate and Repository and Split Repository into Interface and Implementation to separate the database access, or Extract Entity from Smart UI and Extract Service from Smart UI to separate the user interface code.
These refactorings usually take place before or after tactical refactorings to support the strategic refactorings that are carried out.
Enforce Ubiquitous Language
Motivation
Whenever the code uses bad names, obscure technical names, strange abbreviations, or names that do not reflect your current understanding of the domain, change them accordingly. This is part of DDD’s ...