Crafting the Domain Model
Learn how to craft a domain model within hexagonal architecture, ensuring alignment with the problem domain and independence from non-essential implementation details.
In this lesson, we’ll look at some of the things we need to think about as we write the code for our domain model. We’ll cover what kinds of libraries we should and should not use in the domain model, how we deal with application configuration and initialization, and we’ll also think about what impact popular frameworks have.
Creating domain model
Our domain model is the very core of our application and hexagonal architecture puts it up front and center.
A good domain model is written using the language of our users’ problem domain; that’s where the name comes from. We should see the names of program elements that our users would recognize. We should recognize the problem being solved over and above the mechanisms we are using to solve it. Ideally, we}ll see terms from our user stories being used in our domain model.
Applying hexagonal architecture, we choose our domain model to be independent of those things that are not essential to solving the problem. That’s why external systems are isolated. We might initially think that creating a sales report means that we must read a file and we must create an HTML document. But that’s not the essential heart of the problem. We simply need to get sales data from somewhere, perform some calculations to get totals for our report, and then format it somehow. The somewhere and somehow can change, without affecting the essence of our solution.
Get hands-on with 1200+ tech skills courses.