There are several traditional architectures available, and one of the basic issues with these architectures is the coupling of UI and business logic layer to data access.
In the year 2008, to overcome coupling and separation concerns Jeffry Palermo proposed ‘Onion architecture’. Onion Architecture has layers defined from core to infrastructure to control coupling. Its fundamental rule is that all code can depend on layers more central, but code cannot depend on layers further out from the core. In other words, all coupling is toward the center. This architecture is undoubtedly biased toward object-oriented programming, and it puts objects before all others.
In the center we see the Domain Model, which represents the state and behavior combination. Around the Domain Model are other layers with more behavior. The number of layers in the application core will vary, but the Domain Model remains central and since all coupling is toward the center, the Domain Model is only coupled to itself.
The first layer around the Domain Model is where we would find interfaces that provide object saving and retrieving behavior, called repository interfaces. The object saving behavior is not in the application core, however, because it typically involves a database. Only the interface is in the application core. Out on the edges we see UI, infrastructure, and tests. The outer layer is reserved for things that change often. These things should be intentionally isolated from the application core. Out on the edge, we would find a class that implements a repository interface. This class is coupled to a particular method of data access, and that is why it resides outside the application core. This class implements the repository interface and is thereby coupled to it.
The database is not the center. It is external. Externalizing the database can be quite a change for some people used to thinking about applications as “database applications”. With Onion Architecture, there are no database applications.
More on this architecture in my upcoming blogs!