Implementing a Persistence Adapter
In Chapter 1, What's Wrong with Layers?, I ranted about the traditional layered architecture and claimed that it supports "database-driven design" because, in the end, everything depends on the persistence layer. In this chapter, we will have a look at how to make the persistence layer a plugin to the application layer to invert this dependency.
Dependency Inversion
Instead of a persistence layer, we will talk about a persistence adapter that provides persistence functionality to the application services.
The following figure shows how we can apply the Dependency Inversion Principle to do just that:
Figure 6.1: The services from the core use ports to access the persistence adapter
Our application services call port interfaces to access persistence functionality. These ports are implemented by a persistence adapter class that does the actual persistence work and is responsible for talking to the database...