How does this help me build maintainable software?
Building a persistence adapter that acts as a plugin to the domain code frees the domain code from persistence details so that we can build a rich domain model.
Using narrow port interfaces, we’re flexible to implement one port in one way and another port in another way, perhaps even with a different persistence technology, without the application noticing. We can even switch out the complete persistence layer, as long as the port contracts are obeyed.3
3. Switching out the persistence layer: while I have seen it happen a few times (and for good reasons), the probability of having to switch out the whole persistence layer is usually rather low. Even then, having dedicated persistence ports is still worthwhile, because it increases testability. We can easily implement an in-memory persistence adapter to be used in tests, for example.
Now that we’ve built a domain model and some adapters, let’s...