Interfaces

Layers

Domain-Driven Design itself can be successfully applied in variety of software architectural styles. Some are very broad
and tend to define every aspect of the system, others are more focused and try to address a specific demand.

The business framework itself can adapt to several architectural styles. This documentation will focus on the traditional
layered architecture from the Eric Evans DDD book, improved by the usage of the Dependency Inversion Principle.

The layered architecture

The layered architecture is a classical software architecture that is commonly used in Web, enterprise and desktop
applications. In this architecture, the concerns are separated into a stack of well-defined layers.

A strict layered architecture only allows to couple to the layer directly below. It can be used but we recommend a
relaxed layered architecture , which allows any higher-level layer to couple to any layer below it.

Dependency inversion principle

As you can see in the diagram above, all upper layers are coupled to the infrastructure layer where technical aspects
are implemented. This is not desirable in Domain-Driven Design and we can avoid it by applying the Dependency Inversion Principle.

We move the infrastructure layer to the side, where classes implement interfaces defined by other layers.
Technical dependencies are injected through these interfaces:

The interface, application and domain layers are completely decoupled of any technical aspects. The architecture is made
more flexible by allowing different implementations of an interface to be injected.